Re: how can I loop a std::list ?

From: Siemel Naran (SiemelNaran_at_REMOVE.att.net)
Date: 08/12/04


Date: Thu, 12 Aug 2004 16:41:23 GMT


"David Ecker" <david@familie-ecker.net> wrote in message news:D4GSc.2784
> Siemel Naran wrote:

> > Please be aware that the following does not work, and can you tell why?
> >
> > for(iteratorA=list.begin();iteratorA!=list.end();++iteratorA) {
> > if (*iteratorA == 3) list.erase(iteratorA);
> > }
>
> Of course, the iterator is invalid after the erase. It points to a delete
> item.

Right. So do you know how to fix it (assuming you don't want to use
list::remove or are implementing this function)?



Relevant Pages

  • Re: Erase in a map
    ... Charles Zhang wrote: ... as the erase is called, iterator become invalid. ...
    (microsoft.public.vc.stl)
  • Re: Erase in a map
    ... pos = connectionMap.erase; ... as the erase is called, iterator become invalid. ...
    (microsoft.public.vc.stl)
  • Re: remove an item in a STL list
    ... the sequence becomes invalid. ... The iterator returned by erase() points to ... the returned iterator is invalid. ...
    (comp.lang.cpp)
  • Re: Erase in a map
    ... as the erase is called, iterator become invalid. ... const long current; ...
    (microsoft.public.vc.stl)
  • Re: how can I loop a std::list ?
    ... Siemel Naran wrote: ... > There is no operator< for pretty much all iterators. ... the iterator is invalid after the erase. ...
    (comp.lang.cpp)