From: b.l. b. <bl....@ly...> - 2002-08-25 07:17:37
|
-- On Sun, 25 Aug 2002 05:23:50 Ioannis Vranos wrote: > [snip] > >Or better: > >for(map<int, int>::iterator it=foo.begin(); it != foo.end(); it++) >{ > if (you want to delete this particular element) > foo.erase(it); > >} > > >I think that given what you mentioned, incrementing the iterator which >points to an erased element should be valid. > Wrong "The C++ Standard Library" Nicolai M Josuttis Sec 6.6.2: // remove all elements having a certain value for (pos = c.begin(); pos != c.end(); ) { if( pos->second == value) { c.erase(pos++) } else { ++pos; } } Note that pos++ increments pos so that it refers to the next elemant but yields a copy of its original value. Thus, pos doesn't refer to the element that is removed when erase() is called. Brad __________________________________________________________ Outgrown your current e-mail service? Get a 25MB Inbox, POP3 Access, No Ads and No Taglines with LYCOS MAIL PLUS. http://login.mail.lycos.com/brandPage.shtml?pageId=plus |