FAQ 31.07 How should a pointer variable be handled after being passed to delete?The pointer variable should immediately be put into a safe state. After calling delete p, immediately set p = NULL or p = anotherAutoPtr (unless the pointer p is just about to go out of scope). The goal is to prevent a subsequent operation from following the pointer p (which now points at garbage) or calling delete p a second time. Note that setting p = new Fred() is not acceptable, since the Fred allocation may throw an exception before p is changed to a safe state. We recommend setting p = NULL immediately, in case an exception subverts the normal flow of control. |