假设您正在使用这样的嵌套 for 循环遍历列表:
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?
}
}
}
}
怎么保养iter
?