Back9 said:
When my snob co-work is codereviewing my code,
he use an expression on the following code.
//His comments : You must set the ptr values back to NULL after
delete.
I know that it is good practice after deleting a pointer variable, to
set it NULL.
But my question is is it reuqired?
I hope somebody shows me c++ delete rules on this.
Judging by your use of the word "snob", it sounds like the real issue
here is an underlying personal problem between you and your co-worker.
In technical terms, as other people have commented, you are not
obligated to set the pointer to NULL after delete, although it can in
some senses be seen as good practice.
The real issue, then, is how to handle any discussion with your
co-worker in a mature fashion. As a suggestion:
(a) Acknowledge that there are some arguments for what he is saying.
[Get him to listen to what you have to say next, rather than prepare for
a fight]
(b) Observe that it has the potential to hide some double deletion bugs,
so there is something of a trade-off involved. [Make your technical
point without acrimony]
(c) Suggest that it's probably not of great consequence, and perhaps
that the issue might even become moot if you were to use smart pointers
instead (depending on whether they're suitable for your project,
naturally). [Defuse the situation, and show that you are primarily
concerned about the good of the project, rather than having a pointless
fight]
(d) Offer to change your code along the lines described if he feels
strongly about it (it's possible that he doesn't: the comment doesn't
make it clear). If there's anything you want him to do, now is an
excellent time to bring it up (you're clearly implying a quid pro quo,
even if you don't explicitly link the two things). [Try and achieve a
win-win through negotiation, and build understanding for the future]
The bottom line is that the actual issue here is essentially trivial --
your real goal needs to be to maintain a good personal relationship with
your co-worker. If you waste time arguing about things like whether to
set pointers to NULL after a delete or not, your team as a whole will
suffer. Win wars, not battles.
Regards,
Stu