TITLE: Deleting "this" PROBLEM: amb@Apple.COM (A. Michael Burbidge) Even though it works, I am still wondering whether the official language specification says anything about "delete this;" from a constructor. I can't find anything in the ARM about it. RESPONSE: jamshid@ut-emx.uucp (Jamshid Afshar) I can't find anything restricting `delete this;' from constructors either, so I believe it is okay. [stuff deleted] Also make sure that neither you nor the client can derive any new classes from this set of classes. It's no fun being in a constructor whose `this' was deleted during the construction of a base class :-). An easy way to ensure no stack objects can be created *and* that a user cannot derive a new class is to make the destuctor (or all constructors) `private'. RESPONSE: jimad@microsoft.com (Jim ADCOCK) On the contrary, in general this *will not* work. If it not explicitly made illegal, then it should be. Certainly any use of inheritence virtual functions, etc, ... RESPONSE: jamshid@emx.utexas.edu (Jamshid Afshar) [This is a repost. We had a system crash and I don't believe my original followup got out -- please let me know if you're seeing this twice.] Jim failed to quote, and apparently failed to read, the rest of my article where I discuss the problem and offer a remedy: [stuff deleted] Michael asked what the "official language specs" have to say about it, and I answered that the ARM apparently doesn't seem to restrict it. I am not on the ANSI C++ committee so I do not know if restrictions are being considered. Note, I'm not arguing that it is a good practice (in general, I would prefer a flag and allowing creation only with a static member function until exception handling). Jim says that it should be made illegal, but I don't agree with this change for a couple of reasons. It is perfectly safe in leaf classes (and it's easy for the programmer to ensure it is a leaf class or for the compiler to warn that it might not be). Also, the change would not prevent a `delete this' from happening during construction -- the constructor could simply call another member function which does it.