I am running this code
for(vector<Enemy*>::iterator it = enemyVector.begin(); it != enemyVector.end();)
{
if((*it)->getState())
{
delete *it;
it = enemyVector.erase(it);
}
else
{
++it;
}
}
to delete enemies which are flagged as "dead".From what I've gathered when googleing for a couple of days this is the right way to delete with iterators from a vector. BUT when i kill the last item in the vector my program crashes.
I've had this problem for a while (although it went away for a while, but is back now so i'm guessing the problem lies elsewhere in the code).
If this is the right code i am using what other kinds of code can make it crash? Nowhere else in the program do i delete from the vecor the only other interaction with the vector is from code similar to this:
for(vector<Enemy*>::iterator it = enemyVector.begin(); it != enemyVector.end(); it++)
{
(*it)->draw();
}
Basically what i need help with is knowing what to look for since uploading my code would be to much to ask for and i don't expect anyone to look through it all since it's pretty much code.