Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: delete this; return ret;

Thread Tools

Re: delete this; return ret;

Posts: n/a
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

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
"return delete (new int)" compile but "return delete (new X X C++ 4 07-19-2010 05:47 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Can someone tell me why I can't delete this file? and why it blue screens WinXP Pro on delete? zZz Computer Support 1 01-12-2005 02:37 AM
Help: Delete a single carriage return in a file, but not a double carriage return? Steve Anderson Perl Misc 3 06-21-2004 12:48 AM
Cannot Delete, (The Delete Key Won't Work) Lee Something Computer Support 13 10-15-2003 09:51 PM