Ok, this is probably pretty basic, but I've never done it before.
I have a vector of Particle
s, and when they leave the visible screen, I want to erase them. I looked up the erase-remove idiom, but I don't know how to make that work, because I also need to delete the Particle
instances. I tried with backwards iteration, without success:
for ( std::vector<Particle*>::reverse_iterator rit = particles.rbegin(); rit != particles.rend(); ++rit )
{
if ( IsOffScreen((*rit)->pos) )
{
delete (*rit.base());
particles.erase(rit.base());
}
}
At runtime crash, Visual Studio says "iterator cannot be decremented"
. What am I doing wrong? Is there a better way?