I have this code:
class A
{
std::list<Bm_ob servadores;
void function()
{
ApplySendMessag e apply(this, message);
std::for_each(m _observadores.b egin(),
m_observadores. end(),
apply);
}
}
and, ApplySendMessag e::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 (ApplySendMessa ge =
AplicarEnviarMe nsaje):
msvcp80d.dll!st d::_Debug_messa ge(const wchar_t * message=0x005fb f30,
const wchar_t * file=0x005fbb50 , unsigned int line=236) Línea 24 C++
> libcliente.dll! std::list<maevi f::cliente::Obs ervadorGestorEn tidades *,std::allocato r<maevif::clien te::ObservadorG estorEntidades *::_Const_itera tor<0>::operato r++() Línea 236 + 0x17 bytes C++libcliente.dll! std::list<maevi f::cliente::Obs ervadorGestorEn tidades
*,std::allocato r<maevif::clien te::ObservadorG estorEntidades *>
>::_Iterator<0> ::operator++() Línea 399 C++libcliente.dll!
std::for_each<s td::list<maevif ::cliente::Obse rvadorGestorEnt idades
*,std::allocato r<maevif::clien te::ObservadorG estorEntidades *>
>::_Iterator<1> ,maevif::client e::AplicarEnvia rMensaje>(std:: list<maevif::cl iente::Observad orGestorEntidad es*,std::allocato r<maevif::clien te::ObservadorG estorEntidades *>
>::_Iterator<1_ First=0x0249b93 c,std::list<maevi f::cliente::Obs ervadorGestorEn tidades
*,std::allocato r<maevif::clien te::ObservadorG estorEntidades *>
>::_Iterator<1_ Last=0xcdcdcdcd ,maevif::cliente ::AplicarEnviar Mensaje _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.