I'm having trouble ereasing elements from the ptr_vector, sometimes it crashes my program, here is the method where it happens
Here is what I'm trying to do:Code:void Juego::checkState() { Bullet *b; boost::ptr_vector<Entity>::iterator iter; for (int i = 0; i < entities.size(); i++) { if (entities[i].getInst() == inst_bullet) { b = (Bullet*)&entities[i]; if (b->getDestroy()) { iter = entities.begin(); for (int j = 0; j < i; j++) { iter++; } entities.erase(iter); } } } }
Go through the ptr_vector of Entities and if one is a Bullet (which is derived from entity) I call getDestroy() (which will tell me if the bullet must be destroyed, and is not inherited from Entity) if the bullet must be destroyed I erase that bullet from the vector.
As you can see I'm not familiar at all with iterators and boost, how should I do what I want?