Quote:
for(int i = 0; i <= gameSettings.numMonsters; i++){
cout << "Monster " << i+1 << " position: ";
monsterVector.displayPos();
}
This looks suspicious to me. If numMonsters is greater than monsterVector.size(), you'll have problems. Why do you need to track the number of monsters when you can just look at the size of your monster vector? Storing this value separately seems to me like it only adds more things to go wrong.
Also,
Quote:
monsterVector.erase(monsterIter+k);
What is monsterIter? You're not holding on to an iterator into your vector somewhere, are you? Iterators easily become invalidated (say, by calling erase() on the container), so you shouldn't be storing them. And if you have an iterator into your container, why aren't you using that to loop over all the vector elements?
A few other things, now that I think about it:
-Your loop will skip over some monsters as it is currently written. Consider, you have 4 monsters, the second gets removed:
When k = 1, remove monster at index 1.
This will shift everything else in the array down, so the monster at index 2 is now at index 1, etc.
Increment k. k = 2 now, so the monster at index 1 (which was at index 2 prior to this loop iteration) will get skipped over.
-Why do you print the location of every monster every time one gets erased?