映射/设置迭代器在 std::map 中不可递增

map/set iterator not incrementable in std::map

本文关键字:map 映射 设置 迭代器 std      更新时间:2023-10-16

it是循环的最后一次迭代时,在该迭代结束时将抛出此错误。

std::map<std::string,std::shared_ptr<Entity>> entities;
typedef std::map<std::shared_ptr<Entity>,std::vector<std::pair<std::shared_ptr<Entity>,const MTV*>>> colmap;

 

std::map<std::string,std::shared_ptr<Entity>>::iterator it;
for(it = entities.begin();it!=entities.end();++it){
    std::map<std::string,std::shared_ptr<Entity>>::iterator it2;
    for(it2 = entities.begin();it2!=entities.end();++it2){
        MTV* mtv = new MTV(1,sf::Vector2f(1,0));
        collisions[it->second].push_back(std::make_pair(it2->second,mtv));
    }
}

迭代器不可能突然从显示的代码中变得不可递增。必须有一些其他代码导致错误。

相关文章: