Say you're iterating over a list using a nested for loop like this:
for( list<Object>::iterator iter = list.begin() ; iter != list.end() ; ++iter )
{
for( list<Object>::iterator iter2 = list.begin() ; iter2 != list.end() ; ++iter2 )
{
if( iter != iter2 )
{
if( some other condition )
{
iter2 = list.erase( iter2 ) ;
// uh oh! what about iter?
}
}
}
}
How can you maintain iter
?