Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > for_each iteration in a std::list adds a new element and nextiteration crashes

Reply
Thread Tools

for_each iteration in a std::list adds a new element and nextiteration crashes

 
 
Javier
Guest
Posts: n/a
 
      04-18-2008
Hi all,

I have this code:

class A
{
std::list<B> m_observadores;

void function()
{

ApplySendMessage apply(this, message);
std::for_each(m_observadores.begin(),
m_observadores.end(),
apply);
}
}

and, ApplySendMessage:perator() adds a new item to the list
m_observadores under some conditions.

I get (MSVC8.0) "list iterator not incrementable" in an iteration of
for_each algorithm after adding (m_observadores.push_back) a new item
to the list in the previous iteration (ApplySendMessage =
AplicarEnviarMensaje):

msvcp80d.dll!std::_Debug_message(const wchar_t * message=0x005fbf30,
const wchar_t * file=0x005fbb50, unsigned int line=236) Línea 24 C++
> libcliente.dll!std::list<maevif::cliente::Observad orGestorEntidades *,std::allocator<maevif::cliente::ObservadorGestor Entidades *> >::_Const_iterator<0>:perator++() Línea 236 + 0x17 bytes C++

libcliente.dll!std::list<maevif::cliente::Observad orGestorEntidades
*,std::allocator<maevif::cliente::ObservadorGestor Entidades *>
>::_Iterator<0>:perator++() Línea 399 C++

libcliente.dll!
std::for_each<std::list<maevif::cliente::Observado rGestorEntidades
*,std::allocator<maevif::cliente::ObservadorGestor Entidades *>
>::_Iterator<1>,maevif::cliente::AplicarEnviarMens aje>(std::list<maevif::cliente::ObservadorGestorEn tidades

*,std::allocator<maevif::cliente::ObservadorGestor Entidades *>
>::_Iterator<1> _First=0x0249b93c,

std::list<maevif::cliente::ObservadorGestorEntidad es
*,std::allocator<maevif::cliente::ObservadorGestor Entidades *>
>::_Iterator<1> _Last=0xcdcdcdcd,

maevif::cliente::AplicarEnviarMensaje _Func={...}) Línea 28 + 0x8
bytes C++


Is the iterator invalidated after the insertion or my error comes from
another place? Is this standard?

m_observadores.push_front instead of m_observadores.push_back will fix
that?

Thank you.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
James Gosling the Creator of EMACS and JAVA - leaves ORACLE - Butthen reports started coming in of odd failures. Systems would crashstrangely. We'd get crashes in applications. All applications. Crashes in thekernel. small Pox C Programming 2 07-22-2010 10:07 PM
Struts - Problem with nested iteration or double iteration Rudi Java 5 10-01-2008 03:30 AM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
Repeating element string parsing and iteration throwaway43054@gmail.com Perl Misc 3 11-15-2007 10:57 PM
Implicit iteration counter in std::for_each psujkov@gmail.com C++ 2 03-14-2007 05:23 PM



Advertisments