I have this code:
class A
{
std::list<Bm_observadores;
void function()
{
ApplySendMessage apply(this, message);
std::for_each(m_observadores.begin(),
m_observadores.end(),
apply);
}
}
and, ApplySendMessage::operator() 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>::operator++() Línea 236 + 0x17 bytes C++libcliente.dll!std::list<maevif::cliente::Observad orGestorEntidades
*,std::allocator<maevif::cliente::ObservadorGestor Entidades *>
>::_Iterator<0>::operator++() 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.