i am getting glibc detected in the following code can someone please explain it to me
#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;
}
Here on calling cout<<*(s1.ptr)<<endl;
the glib is detected. what i am not able to understand is why even when desructor is not called for s1 the reference is getting deleted.