Let's say I have two containers that hold pointers to the same objects:
std::list<Foo*> fooList;
std::vector<Foo*> fooVec;
Let's say I delete an object from one of these containers through one if its methods are:
std::vector<Foo*>::iterator itr =
std::find( fooVec.begin(), fooVec.end(), pToObj );
fooVec.erase( itr );
CppReference says this calls the object's destructor. Does this mean that the pointer to the object in fooListis a sagging pointer?
I would prefer not to use reference counted pointers. How to deal with this problem?
source
share