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

J

Javier

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::eek: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::ObservadorGestorEntidades *,std::allocator<maevif::cliente::ObservadorGestorEntidades *> >::_Const_iterator<0>::eek:perator++() Línea 236 + 0x17 bytes C++
libcliente.dll!std::list<maevif::cliente::ObservadorGestorEntidades
::_Iterator<0>::eek:perator++() Línea 399 C++
libcliente.dll!
std::for_each<std::list<maevif::cliente::ObservadorGestorEntidades
::_Iterator<1>,maevif::cliente::AplicarEnviarMensaje>(std::list<maevif::cliente::ObservadorGestorEntidades
::_Iterator<1> _First=0x0249b93c,
std::list<maevif::cliente::ObservadorGestorEntidades
::_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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top