I am trying to create a vertically scrolling shooter where when you press space a bullet is created and then when the bullet goes off screen the bullet is destroyed. I keep track of the bullets through vector delcared as vector<BULLET> bullets;
When I try to destroy any bullets that are outside of the screen, I get a ton of errors such as:
c:\mingw\bin\..\lib\gcc\mingw32\4.7.0\include\c++\bits\stl_algobase.h|384| required from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = true; _II = BULLET*; _OI = BULLET*]'|
My code looks like this:
for( auto it = bullets.begin(); it != bullets.end(); ){
if( it->is_dead()){
it = bullets.erase(it);
}else{
it++;
}
}
The part that's frustrating me is that I have similar loop that deletes any game objects that need to be deleted in a vector that holds pointers with:
for( auto it = activeInstances.begin();
it != activeInstances.end(); ){
if( (*it)->is_dead()){
it = activeInstances.erase(it);
}else{
it++;
}
}
and this one works just fine.
Edit: I'm not sure if it makes a difference or not but just for reference I'm adding the section that occurs later in the same function that adds bullets to the vector:
if( key[SPACE] && reload == 0){
reload = reloadTime;
BULLET newBullet;
newBullet.init( x, y);
bullets.push_back( newBullet);
}