Is it allowed to use a pointer's name of a pointer once deleted?
This code, for instance, won't compile.
int hundred = 100;
int * const finger = &hundred;
delete finger;
int * finger = new int; // error: conflicting declaration 'int* finger'
This won't either:
int hundred = 100;
int * const finger = &hundred;
delete finger;
int finger = 50; // error: conflicting declaration 'int finger'
No. The
int *is still an living object. The lifetime of theintthat it pointed to has ended.Note that
has undefined behaviour, as you have attempted to
deletean object that was not allocated bynew.In general,
newanddeleteshould not appear in C++ programs. Owning pointers should bestd::unique_ptr(or rarelystd::shared_ptror other user-defined smart pointer type).