I am currently programming a little game for the console with an 2D map. 2 Elements of my game are: destroying fields and an enemy, which spreads in a random direction (its getting bigger). These two "entities" are saved in a structure which contains two vectors (X and Y). I am now trying to erase an element of "_Enemy"(<-private instance of the structure in a class, same as "_DestroyedFields") if you destroy the field where the enemy is.
I tried a lot of different variations to do so and whats giving me the error least is this method (I already searched the internet for a while now an couldn't find a answer to my question):
for (std::vector<int>::iterator itEX = _Enemys.X.begin(), itEY = _Enemys.Y.begin(); itEX != _Enemys.X.end() && itEY != _Enemys.Y.end(); ++itEX, ++itEY) { for (std::vector<int>::iterator itX = _DestroyedFields.X.begin(), itY = _DestroyedFields.Y.begin(); itX != _DestroyedFields.X.end() && itY != _DestroyedFields.Y.end(); ++itX, ++itY) { if (*itY == *itEY && *itX == *itEX){ itEY = _Enemys.Y.erase(itEY); itEX = _Enemys.X.erase(itEX); } } } PS: sorry if my english isn't the best, im german ^^
PSS: if you wanna watch over my whole code, you can find it on Github: https://github.com/Aemmel/ConsoleGame1
erase...