🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#15
From: Bowden Wise
Date: Fri, 29 Dec 1995 21:40
48 lines
1951 bytes
X-Original-Date: Fri, 29 Dec 1995 16:21:37 -0800

Hi,

I am using the STL to hold a list of items for a DDEML topic.  When
the topic is destroyed, all of the associated items with that
topic are erased from the topic's item list.  Erasing the item
also causes the item's destructor to be called:


BOOL DDETopic::DelAllItems ()
{
#ifdef DEBUGON
Tracer t("DDETopic::DelAllItems ()");
#endif

   for (_itemIter  =   _itemList.begin();
        _itemIter  !=  _itemList.end();
        _itemIter++)
   {
#ifdef DEBUGON
if (__theLog) __theLog->OutputLn ("calling erase for item");
#endif
      _itemList.erase (_itemIter);
   }

   return TRUE;
}

In my particular application the list only contains a single 
element.

When DEBUGON is enabled, the single item is correctly deleted the
first time through the loop.  However, I can also verify that
the loop is entered a second time, thereby resulting in a GPF.

Any ideas why the _itemIter != _itemList.end() test of the for
loop is failing?  Anyone else encountered this?

Bowden
Dept of Computer Science, RPI
wiseb@cs.rpi.edu
http://www.cs.rpi.edu/~wiseb/

    [ 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: <4c1n8o$2jn@netlab.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!kbad.eglin.af.mil!rpi!not-for-mail
From: Bowden Wise <wiseb@cs.rpi.edu>
Newsgroups: comp.lang.c++.moderated,comp.lang.c++,comp.os.ms-windows.programmer.misc
Subject: STL loops through a list with one element more than once!  Why?
Date: 29 Dec 1995 21:40:40 -0000
Organization: Rensselaer Polytechnic Institute, Computer Science
Sender: cppmods@netlab.cs.rpi.edu
Approved: Dietmar.Kuehl@uni-konstanz.de
Message-ID: <4c1n8o$2jn@netlab.cs.rpi.edu>
NNTP-Posting-Host: netlab.cs.rpi.edu