473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Hi all,

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.
Jun 27 '08 #1
0 1698

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike Pemberton | last post by:
I'm sure there's a good explanation for this effect, but I get rather a strange output from this little test: #include <iostream> #include <list> int main() { std::list<int> int_list;
3
by: Kyle Teague | last post by:
I have a list of pointers to structs as a private member of a class. If I call begin() in the same function as I added the data then no access violation occurs. However, if I try to call begin() in...
6
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't...
25
by: Markus Svilans | last post by:
Hi, There seems to be some functionality missing from the STL. I am iterating through a linked list (std::list) using a reverse iterator and attempting to erase certain items from the list. It...
4
by: Tim Slattery | last post by:
It would be convenient for my app to store the stuff I'm generating in a std::list. I'd like to remember the location of a particular place in the list - sort of like sticking my finger into it -...
3
by: Andy | last post by:
Hello, I have the following situation: Thread A is allocating a dataset, doing some low-level calculations and storing a pointer to the dataset in a std::list via push_back. Thread B should...
15
by: desktop | last post by:
If I have a sorted std::list with 1.000.000 elements it takes 1.000.000 operations to find element with value = 1.000.000 (need to iterator through the whole list). In comparison, if I have a...
4
by: TBass | last post by:
Hi, I've got a class that uses a std::list to store tags that need to be written out to a device. I've had no problem with the lists in terms of iterating and reading values. My problem is when...
11
by: Juha Nieminen | last post by:
Assume we have this: std::list<Typelist1(10, 1), list2(20, 2); std::list<Type>::iterator iter = list1.end(); list1.swap(list2); What happens here, according to the standard? 1) 'iter'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.