How do I know if an object has already been deleted through another pointer?

Say pointerA is pointing on object1.
pointerB is also pointing on object1.
I want to do a delete pointerB, but I want to make sure the object hasn't already been deleted through pointerA (or any other pointer for that matter)?
You can check out "Smart Pointers" in the Boost Library:
http://www.boost.org/libs/smart_ptr/smart_ptr.htm

Alternately, if you don't want to mess with Boost, you can just add a reference count to your object. Every time you want to assign a pointer to an existing object, bump the reference count. If you want to delete the object, decrement the reference count. When it hits zero only then should you actually free it. This requires careful overhead...

Hope this helps.
Topic archived. No new replies allowed.