When iterating through an STL::vector of pointers, what is the best practice for deleting objects along the way?
I understand the erase-remove idiom. But since the vector contains pointers, I am concerned that this will only delete the pointer, but leave the instances hanging around in memory.
For example, I would do something like
std::vector<someClass*> someClassList
std::vector<someClass*>::iterator i;
for (i=someClassList.begin(); i != someClassList.end(); ++i){
determine_if_should_be_deleted(i);
// <--How to delete the object and remove it from the vector without
// <--messing up the iterator?
}