vector<T>::iterator
Thomas Kunert
kunert@physik.tu-dresden.de
Thu Jul 31 10:42:00 GMT 2003
Gabriel Dos Reis wrote:
> If you can handle French, here is the part of interest to you:
>
> > }else{
> > _pCoArt.erase(&_pArt);
>
> Il n'y a pas de fonction erase qui prend l'adresse d'une variable
> locale. Avec certaines implémentations (dont g++, la version debug de
> StlPort, et la version debug des Dinkumware récents), cette ligne ne se
> compilera même pas -- erase veut un iterator, non un pointeur. (Dans
> certaines implémentations, un itérateur d'un vector est un pointeur,
> mais la norme ne l'exige pas, et à mon avis, ce n'est pas un bon choix
> dans l'implémentation.)
This is an insufficient solution to the general problem
of ensuring valid iterators. The requirement of erase() is not to have
an iterator of the correct type but to have a pointer pointing into
the correct array. Much more common and more difficult to
find is the case of invalid iterators obtained from different vectors
or from the same vector before a reallocation took place. There
have been rumours about adding accurate array range checking to GCC
for quite some time, this solves the problem much more complete.
Thanks,
Thomas.
More information about the Libstdc++
mailing list