🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.moderated
Article #18

Re: STL loops through a list with one element more than once! Why?

#18
From: Yossef Halakhmi
Date: Mon, 01 Jan 1996 17:47
28 lines
1541 bytes
X-Original-Date: 31 Dec 1995 07:54:48 GMT

In article <4c1n8o$2jn@netlab.cs.rpi.edu>, Bowden Wise <wiseb@cs.rpi.edu> wrote:
 
> BOOL DDETopic::DelAllItems ()
> {
>    for (_itemIter  =   _itemList.begin();
>         _itemIter  !=  _itemList.end();
>         _itemIter++)
>    {
>       _itemList.erase (_itemIter);
>    } 
>    return TRUE;
> }



After any one 'erase' your list is changed and iterator doesn't point to
the objrct that you want . _itemList.end() also will point on something new.
And not to the old value of  _itemList.end() which you have in 
'for' .
If  you want to erase all elements in list/array then use 
erase(iterator forst, iterator last) mem-function

    [ comp.lang.c++.moderated is a moderated newsgroup.  Submit articles ]
    [  to <c++-submit@netlab.cs.rpi.edu>.  The moderation policy can be  ]
    [   retrieved from <http://netlab.cs.rpi.edu/~cppmods/guide.html>.   ]
    [    Moderators can be reached at: c++-request@netlab.cs.rpi.edu.    ]
Technical Details
Message-ID: <4c96nl$1tr@netlab.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
References: <4c1n8o$2jn@netlab.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
From: yossef@ird.scitex.com (Yossef Halakhmi)
Newsgroups: comp.lang.c++.moderated,comp.lang.c++,comp.os.ms-windows.programmer.misc
Subject: Re: STL loops through a list with one element more than once!  Why?
Date: 1 Jan 1996 17:47:33 -0000
Organization: Scitex Corp.
Sender: cppmods@netlab.cs.rpi.edu
Approved: Dietmar.Kuehl@uni-konstanz.de
Message-ID: <4c96nl$1tr@netlab.cs.rpi.edu>
References: <4c1n8o$2jn@netlab.cs.rpi.edu>
NNTP-Posting-Host: netlab.cs.rpi.edu