此方法会导致中止错误:"map/set iterator not incrementable."
由于在if
失败并且确定应该擦除的有效迭代器(并且是)之后,通过++_iter
失败继续到映射中的下一个迭代器,因为_iter
不再是有效的对象/指针。
遍历地图并能够在整个过程中删除单个项目的正确程序是什么?
typedef std::map<std::string, BITMAP*> MapStrBmp;
typedef MapStrBmp::iterator MapStrBmpIter;
\\...
void BitmapCache::CleanCache() {
//Clean the cache of any NULL bitmaps that were deleted by caller.
for(MapStrBmpIter _iter = _cache.begin(); _iter != _cache.end(); ++_iter) {
if(_iter->second != NULL) {
if((_iter->second->w < 0 && _iter->second->h < 0) == false) continue;
}
_cache.erase(_iter);
}
}