What will exactly happen if a member function try to do delete this;, like in the constructor of the following class?
class A
{
public:
A(int);
~A();
int *pi;
}
A::A(int i)
{
delete this;
pi = new int(i);
}
A::~A()
{
delete pi;
}
This C++ FAQ entry answers this quite nicely, repeating here:
As long as you’re careful, it’s OK for an object to
delete this.Here’s how I define "careful":
You are violating the #3 by accessing
piafterdelete this