Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: delete this; return ret; (http://www.velocityreviews.com/forums/t267660-re-delete-this-return-ret.html)

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()
{
InternlockedDecrement(&m_nRef);
if( m_nRef == 0 )
{
delete this;
return 0; // can't access m_nRef anymore
}
else
return m_nRef;
}

--
Unforgiven

"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.