Hey there, I have just started using the in-built Lists.
I have a list of bullets for an asteroid game and can check through the list updating and drawing where needed except when I goto clear a bullet from the list (if its time remaining has run out), I get a nasty compiler error. I don't see what is wrong with my code though.
//check if current bullet in list needs to be deleted
void Ship::checkBullet()
{
list<Bullet>::iterator it;
it = bulletRegister.begin();
while(it != bulletRegister.end())
{
if (it->shouldDelete()) //check if bullet has run out of time
{
if (g_debugMode)
{
cout<<"A bullet was deleted from the bullet register. There are now "<<bulletRegister.size()<<" bullets still active\n\n";
}
bulletRegister.erase(it); //If I comment this out it works fine (obviouslly without destroying the bullet
}
else //if not update the position
{
it->updatePosition();
}
//check if there are any more bullets to traverse through
if (!bulletRegister.empty())
{
it++;
}
}
}