Possible Duplicate:
Is there any reason to check for a NULL pointer before deleting?
I know that The C++ language guarantees that delete p will do nothing if p is equal to NULL. But constantly in different projects, articles, examples I see that it is checking for NULL before delete. Usually in format
if(pObj)
delete pObj;
Why is it so? Some historical reasons? I’m totally confused about how to do delete objects right.
Ignorance. Some people do not know that
delete(NULL);is not doing anything.You can not really check if the pointer is really valid. If you delete twice, you are invoking an undefined behavior.