I have a global singleton that is used by many objects in my program. This is causing crashes when the program is shutting down – it is used in the destructors of some objects, after the singleton itself has been destructed by end-of-program. Is there a portable way to tell if a pointer has had ‘delete’ called on it? In my case, it looks like delete changes the value of the pointer to (void*)(-1), but I don’t know if this is portable.
Share
No, it is not possible to tell if the object pointed to by a C++ pointer has been destroyed.
You can use smart pointers, which handle it automatically.