The following code behaves fine on my mac but on my linux, it results in segmentation fault.
std::list<sock>::iterator iter;
for(iter = sock_list.begin(); iter != sock_list.end(); ++iter) {
if ((*iter).fd == param1) {
sock_list.erase(iter);
}
}
After searching a bit, I found out that this makes it work on my linux too by adding -- at line 4.
std::list<sock>::iterator iter;
for(iter = sock_list.begin(); iter != sock_list.end(); ++iter) {
if ((*iter).fd == param1) {
sock_list.erase(iter--);
}
}
Although I made it work, I'm still curious why they behave differently. Both have gcc 5.x and c++ 11.