我在以下代码中检测到 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;
glib 被检测到。我无法理解的是,为什么即使没有为 s1 调用desructor,引用也会被删除。