Afficher un message
Vieux 22/02/2008, 08h47   #10
Triple-DES
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector.erase(iterator iter) will change "iter" or not?

On 22 Feb, 08:31, Old Wolf <oldw...@inspire.net.nz> wrote:
> On Feb 22, 4:31 am, Richard Herring <junk@[127.0.0.1]> wrote:
>
> > In message <fpk2sg$5d...@news.datemas.de>, Victor Bazarov
> > >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.

>
> > I wonder if the OP is confused because the iterator is passed by value
> > and therefore not modified? Obviously erase(iter) can't change its
> > _value_, but it certainly changes its _meaning_ - what it points to is
> > no longer valid.

>
> The value certainly is changed: previously it was
> well-defined and now it is indeterminate! It doesn't
> point anywhere; it's nonsensical to say that what
> it points to is not valid. Perhaps you mean to say
> that the representation isn't changed;


That's an interesting point. Consider:
int * p = new int(441);
delete p;

Would you say that the last line changes the value of p?

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