I have the following code segment:
std::list<reply_t> l = m[index];
for (std::list<reply_t>::iterator it = l.begin(); it != l.end(); it++) {
// do something
}
and
std::list<reply_t> *l = &(m[index]);
for (std::list<reply_t>::iterator it = l->begin(); it != l->end(); it++) {
// do something
}
m is just a map with int index and list as values, ie std:map<int, std::list<reply_t> >
.
The two versions ONLY differ in how the list is being referred to, ie one by pointer one by object. Everything else in my code is exactly identical. HOWEVER, when I run with these two versions, version 1 consistently fails tests and version 2 consistently succeeds. The code is used in a multi threaded context, if that helps.
I'm new to c++ and this is just completely bizarre to me. Anyone with an possible explanation?