I get a syntax error for everything I try. Can someone please tell me what to put in place of the comment? This is my first time working with vectors.
EntityList is a static vector of the Entity class.
for(int i = 0;i < (int)Entity::EntityList.size();i++) { if(!Entity::EntityList[i]) continue; if(Entity::EntityList[i]->isDead){ //Erase from vector //Decrement i? } Entity::EntityList[i]->OnLoop(); } What should I put in place of the comment? I've tried a few things but nothing works. For example, Entity::EntityList.erase(i); doesn't work. I get the following error, which I don't understand:
cannot convert parameter 1 from 'int' to 'std::_Vector_const_iterator<_Myvec>'
All the examples I see use ints for the parameter, so I don't know what to do.
Also, since elements in the vector are shifted down after removal, should I decrement i after removing an item so it performs the loop with the same value again? Or is there a more elegant way of doing it?
std::vector::eraseusing anintargument, they're wrong. It takes an iterator. cplusplus.com/reference/stl/vector/erase