Please consider the following code:
class foo { public: foo(){} ~foo(){} void done() { delete this;} private: int x; };
What is
This question has been answered but I will add a new point that if your class does call delete this then you should also make the destructor private.
This ensures that only the class can delete itself.
If you make your destructor private above, both of your code samples will fail to compile.