I think that this is not official C++ behaviour, so you should not depend on it. This is what happens:
new allocates some memory for a new object, and returns a pointer to that memory. Delete de-allocates that memory, but the pointer is still pointing to the (de-allocated) memory location. Using that pointer results in undefined behaviour. In your case it just works, but you might get a segmentation fault on other platforms.
What happens if you call a method of an object, is that some executable code is executed, like a normal C function, and a pointer to the object itself is given to the nethod as an argument with the name "this". Your method f doesn't use this, or any member variables of the class, so in this case it doesn't matter for f() that the this-pointer points to de-allocated memory.
|