In these days, I used STL in a project, and met several problems. One was caused by erase method. As we know, when we delete a element in a container in STL, the iterator itself will be changed, so the the iterator should be set correctly. A right method can be used as following:
Typedef list<MyClass*>::Iterator myIter;
for(myIter it = listObj.begin(); it != listObj.end();)
if(true)
it = listObj.erase(it);
else
++it;