class A
{
int x;
public:
A(){}
~A()
{
cout<<this<<endl<<"bye"<<endl;
}
};
int main()
{
A a;
a.~A();//bye
return 0;
// after return 0, destructor will be called and bye will be printed again
}
the destructor gets called twice. The 1st time, its explicitly called and the second time, its called
after return 0.
in both the cases, the same addr of 'this' is printed.
As a destructor releases memory for an object, here it seems to be freeing the 'this' pointer
twice , which should cause a problem. However, the program executes smoothly.
Can some one explain this ?