vector iterators incompatible

此生再无相见时 提交于 2019-12-05 12:11:14

My guess, given limited context you provided, is that neighbours() returns copy of std::vector<edge*>, instead of reference, i.e. std::vector<edge*>&. So after begin() call temporary object is disposed, and obtained iterator points to rubbish.

I would guess that remove_edge modifies the underlying container of neighbor_it, thereby invalidating it, but I cannot be certain without seeing more of your code.

If this is a case, a possible solution would be to return an iterator to the next element after the deleted one, as done for instance by std::vector::erase.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!