And i was doing something like this:
for( iter = mylist.begin(); iter != mylist.end(); iter++ )
if( ( *iter ).getdays() > cround ) // It will still exist on map
( *iter ).factor();
else mylist.erase( iter );
So i was getting a segmentation fault because i didnt know that when deleting an item in a list, the iterator is also deleted.
But i have randomly fixed it before by just doing iter++ inside the erase function. Heres the code:
for( iter = mylist.begin(); iter != mylist.end(); iter++ )
if( ( *iter ).getdays() > cround ) // It will still exist on map
( *iter ).factor();
else mylist.erase( iter++ );
But now that i know that about iterators, i cant see why it keeps working.( i tested with many items and everything is working perfectly )
Any explanation to this ?
Thanks in advance

New Topic/Question
Reply




MultiQuote











|