Velocity Reviews

Velocity Reviews (
-   C++ (
-   -   Re: delete this; return ret; (

Unforgiven 06-24-2003 01:46 PM

Re: delete this; return ret;
Wenjie wrote:
> Hello,
> In other words, will //LABELED line
> be executed? My confusion is that the
> object should have been destructed at
> that time.

Yes it will. You can't access any member variables after delete this, but it
doesn't affect the execution of the code. The only requirement of course is
that your object is on the heap (constructed with new), not on the stack.

In fact, when implementing a Microsoft COM component, it's the most common
way of implementing IUnkown::Release():

STDMETHODIMP_(LONG) SomeObject::Release()
if( m_nRef == 0 )
delete this;
return 0; // can't access m_nRef anymore
return m_nRef;


"Not only do I not know the answer
I don't even know what the question is"
My world - Metallica

All times are GMT. The time now is 03:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.