When I execute the following code, I am getting map/set iterators not incrementable error.
typedef std::multimap<int, int> MapType;
assgnt::MapType my_map;
assgnt::MapType::iterator it;
for(it = my_map.begin(); it != my_map.end(); )
{
my_map = obj1.addGoodNeighbours(it->first, it->second, my_map);
++it;
}
Please help
I don’t know what a
assgnt::MapTypeis, but assigning anotherassgnt::MapTypetomy_mapinside the for loop, can’t be a good thing:You should at least reassign the iterator:
But i believe that code is far from correct. You are basically destroying the structure that you’re iterating while iterating it.
EDIT: Well we do know what a MapType is now. All of the above is still correct. You can’t just re-assign your maps while iterating them.