void TankFactory::updateAllTankStatus(float time){ for (TankIterator t = tankList.begin(); t != tankList.end();){ //t shouldn't be increment in for loop, may cause program crashes. Tank* tank = *t; tank->update(time); if (tank->ifExplodeFinished()) { if(tank->getType() != TANK_PLAYER){ //delete tank destroyTank(tank); Tank* tmp = tank; t++; tankList.remove(tmp); }else{ destroyTank(tank); Tank* tmp = tank; t++; tankList.remove(tmp); rebornPlayer(); } } else { t++; } } }
void TankFactory::clearAll(){ //exception is player tank for (TankIterator t = tankList.begin(); t != tankList.end();){ //t shouldn't be increment in for loop, may cause program crashes. Tank* tank = *t; if(tank->getType() == TANK_PLAYER){ playerTank = NULL; } t++; destroyTank(tank); tankList.remove(tank); } //tankList.clear(); }