Mathieu Malaterre <mm******@nycap.rr.com> wrote in news:rKK0d.22388
$2*******@twister.nyroc.rr.com:
Hello,
I am trying to override the delete operator so that it set 0 to my
object. Is this possible ?
I am used to do:
obj *a = new obj;
...
delete a;
a = 0; //prevent any misuse.
But I am looking for a transparent way to do it.
Thanks,
Mathieu
This would be of dubious value since you can have multiple variables
pointing to the same object, and you would also have to handle the case
where the pointer is not even stored in a variable at all, e.g.
delete ptr + 1;
If you still wanted to go ahead with the idea, you probably can't do it
by overloading operator delete. You would have to introduce a smart
pointer type that overrides ->.
Gregg