I'm having a problem when deleting a pointer in a destructor. The pointer is a member variable in a class. I initialize it in a member function and delete at the end of the same function. However, I also have included the delete pointer statement in the class destructor just in case. The problem is that if all goes well the pointer gets deleted in the function and then the destructor throws an exception because the pointer is invalid. How can I tell if the pointer is valid and that the memory is already free? Checking if the pointer is 0 doesn't seem to work. What am I missing?
Also, if I have another pointer defined locally in a function and I use new to initialize it, how can I call delete if an exception is thrown before the delete statement is encountered?