Hi. Im having a problem with a function in my class that uses vectors and iterators. I know it is this function as when I comment it out it works fine. I am trying to set the x and y positions back to the start when the objects in question move off the screen. Btw, the error is a run time error. "vector iterator not incrementable". Thanks in advance. Here is my code.
an iterator isn't an integer and you can't treat it like an integer. So this, " iter++ " is impossible.
may i suggest this instead?
1 2 3 4 5 6 7 8 9 10 11 12
void EnemyManager::initialize()
{
for (int i = 0; i < (int) enemiesVec.size(); i++)
{
enemiesVec[i]->setIsActive(true);
if(enemiesVec[i]->getIsActive() == true)
{
enemiesVec[i]->setSpriteX(x);
enemiesVec[i]->setSpriteY(y);
}
}
}
EDIT: actually, what i said was entirely incorrect, and what you did should work right, just went over the documentation again :} fail. Back to what webJose asked...
Thanks for everyones help. I fixed it. It tried a public declaration of the iterator and it works. Strange really because im still using "iter" elsewhere in the class, only in that 1 function do I need to change how it's done. Here is my amended code.
When incrementing an iterator use the prefix ++ instead of the postfix ++. The postfix ++ creates a temporary variable before incrementing the iterator, while the prefix just increments the iterator. The code for the for statement should look like the following:
for(it = enemiesVec.begin(); it < enemiesVec.end(); ++it)