News for hackers. Stuff that matters.
Re:The Best C++ Interview Question – Ever by DanielBMarkham on Monday December 07, 2009 @06:37PM (#982529)
I'm cold on C++ (haven't coded in several years) but let me try this out:

deleting "this" releases memory held by the instance data of the object. The programmer can't be sure that any subsequent references to that data will return valid data (although the compiler will allow it). Static data and type-level methods should be fine to call -- although every time the program counter ticks you can't be sure that you're continuing to walk through uncontaminated memory.

I think that's it.

Sounds like a BS question to me because you're going way, way under the hood with exactly how the compiler runs the code. It's like those coding questions where you have to start byte-counting to get the answer. Neat trivia perhaps, but I'd much rather have somebody who delivered clean, organized, easily-maintainable code and got the answer wrong.

EDIT: Seems like I've seen delete this on several occasions (although I can't remember where), but hell if I'd use it unless I had no choice. Even then, it'd be the last statement in the method.

Re:The Best C++ Interview Question – Ever by tptacek on Monday December 07, 2009 @07:03PM (#982588)
It also invokes the dtors for the object, and, more importantly, does all this before the caller method returns, so that when "delete this" finishes, the program still has to execute code in the method context of a dead object --- which usually works.
Re:The Best C++ Interview Question – Ever by nvoorhies on Tuesday December 08, 2009 @12:44AM (#983121)
I'm a bit rusty on my C++ minutiae, but... there's also the problem that you don't know whether the corresponding new statement was plain new, new[], etc.

Mismatches between new[] and delete will generally just fail to call dtors or potentially call dtors twice, but the behavior's undefined. Ick.

Re:The Best C++ Interview Question – Ever by machrider on Monday December 07, 2009 @07:05PM (#982592)
The function's body is not part of the object itself. When you delete the object, you can keep executing the function just fine, as long as you don't access any member variables.
Re:The Best C++ Interview Question – Ever by haseman on Monday December 07, 2009 @07:21PM (#982628)
You keep executing the function because it's on the stack. The program counter keeps moving through the method until it hits a return statement. God help you if you try to reference one of the class' internal data objects as their heap space could have been allocated to something else running on another thread.
Re:The Best C++ Interview Question – Ever by DanielBMarkham on Tuesday December 08, 2009 @07:40AM (#983554)
The function's body is not part of the object itself

Most all of the time, yes. But the function could have been dynamically allocated to an instance of the object. You don't know from the definition of the question. A dynamic function, presumably, would be picked up by the dtor.