Please consider the following code:
class foo
{
public:
foo(){}
~foo(){}
void done() { delete this;}
private:
int x;
};
What is happening (and is it valid?) in the following two options:
option 1:
void main()
{
foo* a = new foo();
a->done();
delete a;
}
option 2:
void main()
{
foo a;
a.done();
}
Will the second delete a;
statement at option 1 will cause an exception or heap corruption?
Will option2 cause an exception or heap corruption?