Say I have two containers storing pointers to the same objects:
std::list<Foo*> fooList;
std::vector<Foo*> fooVec;
Let's say I remove an object from one of these containers via one if its methods:
std::vector<Foo*>::iterator itr =
std::find( fooVec.begin(), fooVec.end(), pToObj );
fooVec.erase( itr );
CppReference says that this calls the object's destructor. Does this mean that the pointer to the object in fooList
is a dangling pointer?
I'd prefer not to use reference counted pointers. How can this problem be handled?