On Apr 11, 11:33 pm, Rafael Anschau <rafael.ansc...@[EMAIL PROTECTED]
> wrote:
> I read that you should assign null (0) to all pointers that you call
> delete on.
In general, that should not be needed. Pointers should be members of a
class.
Hence, they are deleted in the destructor and possibly in assignment.
In the destructor case, the pointer itself will disappear soon, so there
is
no point in that last write, as you suspected.
If a class has an assignment operator implemented, it will typically
replace
the pointer with a new'ed value, not 0. It's a good idea to only delete
the
old value once you have a new value. That way, if new fails, the
assignment
fails but the object still has its old value.
The assignment technique is useful for methods in general: first do all
the things that can fail, but do not alter the users object. Iff they
all succeeded, make the modifications to the object in a way that cannot
fail.
HTH,
Michiel.
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|