當我得到下面的代碼檢測的glibc有人可以解釋給我爲什麼雙重釋放或腐敗複製對象
#include<iostream>
using namespace std;
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
void PrintVal()
{
cout << "The value is " << *ptr<<endl;
}
~Sample()
{
cout<<"CALLED\n";
delete ptr;
}
};
void SomeFunc(Sample x)
{
cout << "Say i am in someFunc " << endl;
x.PrintVal();
//cout<<*(s1.ptr)<<endl;
}
int main()
{
Sample s1=10;
cout<<*(s1.ptr)<<endl;
SomeFunc(s1);
cout<<"HERE\n";
cout<<*(s1.ptr)<<endl;
}
這裏就調用cout<<*(s1.ptr)<<endl;
檢測油嘴檢測偶數。我無法理解的是爲什麼即使當s1沒有調用desructor時,引用也會被刪除。
由於沒有遵循[三條規則](http://stackoverflow.com/questions/4172722/what-is-the-rule-of-reeree)的雙刪除。 – Mat 2013-05-05 19:49:05
提拉克,你看到的錯誤信息說「像glibc檢測到[某些問題] ...」 - 這是你應該注意的問題,而不是「檢測到glibc」。 Glibc是檢測到問題的東西。 Glibc不是問題。 – Mat 2013-05-05 19:50:36
是啊對不起它「./a.out:雙重免費或腐敗(fasttop)」這是什麼意思? – 2013-05-05 19:52:12