梦想的天堂

常用链接

统计

最新评论

Erase method in STL

 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;
      
      

posted on 2007-05-03 17:22 IT民工 阅读(296) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理