map/set iterator not incrementable
2014-01-13 22:24
387 查看
1、报错
“map/set iterator not incrementable”,程序运行至一般报错for (ActionBindings::const_iterator cit = _bindings.begin(); cit != _bindings.end(); cit++) { if (actionType == (*cit).second._type) { cit = _bindings.erase(cit); } }在cit++这行报错。
2、内码解析
当执行完erase之后,cit已经指向空,无法进行++操作。在C++11中,std::map/vector的erase方法返回iterator,能够指向被删除的下一个。(The other versions return an iterator to the element that follows the last element removed (or
map::end, if the last element was removed).)
3、解决方案
执行完erase,保存cit用于指向下个对象ActionBindings::const_iterator cit = _bindings.begin(); while (cit != _bindings.end()) { if (actionType == (*cit).second._type) { cit = _bindings.erase(cit); } else { cit++; } }
相关文章推荐
- map/set iterator not incrementable set/map使用erase时注意事项!
- map/set iterator not dereferencable
- VS2008 下 map/set iterator not dereferencable
- map/set iterator not dereferencable
- map/set iterator not dereferencable异常
- STL 二分查找抛出错误(map/set iterator not dereferencable)
- 使用C++的map容器遇到的bug(map/set iterator not dereferencable)
- 使用C++的map容器遇到的bug(map/set iterator not dereferencable)
- 错误map/set iterator not dereferencable
- map/set iterator not dereferencable
- [C++杂记] map/set iterator not dereferencable异常
- C++学习之路(14)---vector报错:vector iterator not incrementable"或"vector iterator + offset out of range"
- Collection集合之六大接口(Collection、Set、List、Map、Iterator
- import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.TreeMap; /*
- 4.1 Collection,List,Set,Iterator,Map
- The requested list key 'map' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or peopl
- List、Set及Map的读取数据---Iterator遍历
- 报错处理:could not be resolved as a collection/array/map/enumeration/iterator type
- list使用中遇到的erase问题(List Iterator Not Incrementable)
- map和set(关于iterator失效的问题)