Suicidal objects

Mike vertex at gmx.at
Sun Dec 9 12:33:24 PST 2007


Out of curiosity I decided to try out how objects could delete themselves  
and what happened if they did. I found out that "delete this;" actually  
works.

AFAIK there's no placement new in D, which could be a reason for allowing  
this behavior. Other than that, any attempts to delete or assign to "this"  
should be illegal inside methods. It's a minor thing - I don't think  
"delete this;" is a common typo and any sane programmer wouldn't do that  
on purpose.

So: what do you think? Are there any useful applications for  
assigning/deleting "this"?

-Mike

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list