Please consider the following code:
class foo
{
public:
foo(){}
~foo(){}
void done() { delete this;}
private:
int x;
};
What is
I would be very cautious about the context in which you free memory. Whilst calling "delete this;" will attempt to free the memory associated with the class structure, that operation has no means of deducing the context of the original memory allocation, ie, if it's allocated from the heap or the stack. My advise would be to rework your code so that the deallocation operation is invoked from an external context. Note that this is different from deallocating structures internal to the class, in that case, use the destructor.