I have a problem with the "map/set iterator not incrementable" error related to my multimap. I have tried googling for answers, but the answers did not help me. I'm assuming that the problem is because first part of my code executes the "akcja" command, which may (but doesn't have to) delete one of the components of multimap:
while ((c = getch()) != 27)
{
if (c == 'n')
{
typedef multimap<int, Organizm*>::iterator iterator;
for (int i = 10; i>= 0; i--)
{
std::pair<iterator, iterator> iterpair = kolejnoscRuchu.equal_range(i);
iterator it = iterpair.first;
for (; it != iterpair.second; ++it)
{
if(it->second->inicjatywa !=0)
{
it->second->akcja();
}
}
}
}
If certain conditions are met the akcja() will trigger the command which removes the element:
void Swiat::usunOrganizm(Organizm *organizm)
{
this->organizmy[organizm->pozycja.x][organizm->pozycja.y] = NULL;
typedef multimap<int, Organizm*>::iterator iterator;
std::pair<iterator, iterator> iterpair2 = this->kolejnoscRuchu.equal_range(organizm->inicjatywa);
iterator it2 = iterpair2.first;
for (; it2 != iterpair2.second; ++it2)
{
if (it2->second == organizm)
{
cout << "usuwam " << it2->second->rysowanie() << endl;
kolejnoscRuchu.erase(it2);
delete organizm;
break;
}
}
}
I've added a "cout << "usuwam " << it2->second->rysowanie() << endl;" part to confirm if the error occurs after removing any elements from my multimap. I would appreciate any help