OT: Calling delete on 'this' from member function

Vladimir Panteleev thecybershadow at gmail.com
Sun May 13 15:50:43 PDT 2007


On Sun, 13 May 2007 18:23:13 +0300, Regan Heath <regan at netmail.co.nz> wrote:

> One further question, is it actually valid to call delete this in a non-static method of a class as shown below.  It seems to work but I would not have thought it possible...

I don't see why this wouldn't work, with the condition that you don't access class fields or virtual methods after deleting the object (this includes invariants). The above might work in very specific circumstances, but you should never rely on accessing data marked as deallocated.

-- 
Best regards,
  Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list