Afficher un message
Vieux 23/02/2008, 23h21   #19
Old Wolf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: vector.erase(iterator iter) will change "iter" or not?

On Feb 23, 6:40 am, James Kanze <james.ka...@gmail.com> wrote:
> unsigned char before[ sizeof( std::vector<int>::iterator ] ;
> memcpy( before, &iter, sizeof( std::vector<int>::iterator ) ) ;
> v.erase( iter ) ;
> memcmp( before, &iter, sizeof( std::vector<int>::iterator ) ) ;
>
> the memcmp will return a value not equal to 0.


How does that work? I agree that it's legal, but I wouldn't
expect it anywhere except the DS9000; it seems that the
implementation, when faced with vector::erase, would have
to go out of its way to go and change bits in the original
'iter' that the parameter to vector::erase was copied from.

> And trying to use the iterator will cause a core dump.


To be expected when using indeterminate 'values'.
  Réponse avec citation
 
Page generated in 0,04553 seconds with 9 queries