I'm iterating over a list and I want to remove certain elements from the list but because the list is resizable I'm not quite sure how to do it. In java I would think to use a list iterator. Here's my basic code:
But the list resizes so if I remove the last element then it will never equal to myQueue.end(). The thing I don't understand is, does myQueue.end point to the last element in the list? I've seen this type of loop used a lot to iterate over a loop but it looks like it will always miss the last element because of the != case, unless the for condition is evaluated at the end.Code:for(list<Obj*>::iterator it = myQueue.begin();it!=myQueue.end();it++)
{
if(some condition)
{
myQueue.erase(it);
it--;
}
}