c++ - vector::erase causing strange behavior -


i trying create vertically scrolling shooter when press space bullet created , when bullet goes off screen bullet destroyed. keep track of bullets through vector delcared vector<bullet> bullets; when try destroy bullets outside of screen, ton of errors such as: c:\mingw\bin\..\lib\gcc\mingw32\4.7.0\include\c++\bits\stl_algobase.h|384| required '_oi std::__copy_move_a(_ii, _ii, _oi) [with bool _ismove = true; _ii = bullet*; _oi = bullet*]'|

my code looks this:

for( auto = bullets.begin(); != bullets.end(); ){     if( it->is_dead()){         = bullets.erase(it);     }else{         it++;     } } 

the part that's frustrating me have similar loop deletes game objects need deleted in vector holds pointers with:

for( auto = activeinstances.begin();  != activeinstances.end(); ){     if( (*it)->is_dead()){         = activeinstances.erase(it);     }else{         it++;     } } 

and 1 works fine.

edit: i'm not sure if makes difference or not reference i'm adding section occurs later in same function adds bullets vector:

if( key[space] && reload == 0){     reload = reloadtime;     bullet newbullet;     newbullet.init( x, y);     bullets.push_back( newbullet); } 

your code fragements differ:

if( it->is_dead()){ 

vs.

if( (*it)->is_dead()){ 

Comments