delete this

Started by
13 comments, last by Corrail 20 years ago
quote:Original post by RenderTarget
if( -- m_cRefCount == 0 )  delete this;return m_cRefCount;  



Though of course, if you take that fallthrough approach, you''d probably want to save m_cRefCount to a temporary variable; who knows whether it will still be valid after deletion...

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Advertisement
Sneftel: No, suicide is never a solution

Having a private constructor? Ok, give me an example of this.

Ok, it might be useful but there must be better solutions and c++ is not really OO. But it''s like when I see a printf-statement in c++ code, I still go bezerk.
quote:Original post by Corrail
Just wanted to know if this command is legal in a method of a class of struct:

delete this;


It is legal, but it is rarely a good thing to do.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
sorry, i know this is an old thread but someone asked why one would ever use a private constructor. one good example of this is when implementing the singleton design pattern.

-j
Jonathan Makqueasy gamesgate 88[email=jon.mak@utoronto.ca]email[/email]
They''ll be happy to hear that.

"Sneftel is correct, if rather vulgar." --Flarelocke

This topic is closed to new replies.

Advertisement