Afficher un message
Vieux 21/02/2008, 15h46   #2
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector.erase(iterator iter) will change "iter" or not?

thomas wrote:
> suppose I will delete an element pointed to by "iter".
> like this:
>
> vector<int> s;
> for(vector<int>::iterator iter=s.begin(); iter!=s.end(); iter++){
> if(*iter==3)
> s.erase(iter); //A
> }
>
> in line A, if element by "iter" is erased, will "iter" point to the
> next element(now should be the current element) automatically?


The iterator that refers to the removed element and all elements
after the removed one are invalidated by that operation. IOW, the
Standard makes no attempt to define what the 'iter' would point to
after being erased.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


  Réponse avec citation
 
Page generated in 0,05103 seconds with 9 queries