What's wrong with my vector?

Started by
11 comments, last by Hedos 20 years, 1 month ago
Here''s the standard algorithm for iterating through a vector and checking a condition for erasing the cell we''re currently looking at:

int i = 0;	while (i != MyVector.size())	{		if(CONDITION)		MyVector.erase(&MyVector[i]);		else // we only move i forward if we did not erase a cell because erasing a cell shifts the entire vector backwards		i++;	}
Advertisement
quote:Original post by Enokh
Here''s the standard algorithm for iterating through a vector and checking a condition for erasing the cell we''re currently looking at:


"The standard" algorithm for iterating through a vector doesn''t involve iterators? Ok...
quote:Original post by Enokh
Here''s the standard algorithm for iterating through a vector and checking a condition for erasing the cell we''re currently looking at:

int i = 0;	while (i != MyVector.size())	{		if(CONDITION)		MyVector.erase(&MyVector[i]);		else // we only move i forward if we did not erase a cell because erasing a cell shifts the entire vector backwards		i++;	}
That won''t even compile under the compiler I use. &MyVector[i] is not necessarily an iterator and should not be passed to erase.

This topic is closed to new replies.

Advertisement