Internally it is simple.
delete this
=
call ThisClass::~ThisClass () ; // Destructor
free (this) ; // deallocation
It's like you're calling from anywhere else.
Of course , "delete this" must be the last statement using object
members(data or function) in the procedure you are in, because "this"
pointer is no more valid after the deletion.
delete this is usually usefoul with reference counted objects (as in
COM), but I won't suggest it's use anywhere else. You could probably
see a "delete this" in the Release function of COM objects.
Good bye
QbProg
Carl Daniel [VC++ MVP] - 19 Oct 2007 15:32 GMT
> Internally it is simple.
>
[quoted text clipped - 11 lines]
> COM), but I won't suggest it's use anywhere else. You could probably
> see a "delete this" in the Release function of COM objects.
One other thing to mention about 'delete this' - it's treading very close to
undefined behavior, but it's a commonly used idiom. The key to having it
work is that 'delete this' must be the very last statement executed in the
function. Any further use of the object afterwards has undefined behavior.
-cd
George - 19 Oct 2007 15:51 GMT
Thanks cd,
Your experience is very helpful.
regards,
George
> > Internally it is simple.
> >
[quoted text clipped - 18 lines]
>
> -cd
George - 19 Oct 2007 15:48 GMT
Thanks QbProg,
Your reply is helpful.
regards,
George
> Internally it is simple.
>
[quoted text clipped - 14 lines]
> Good bye
> QbProg