http://www.cnblogs.com/gshlsh17/
The Rase () method is to delete the node specified by iterator but be aware that iterator is destroyed when the function is executed so that the operation on iterator will be an error. The following is the correct use of the erase () method
Correct use of Method 1:
std::list< int> list;std::list< int>::iterator itlist;for (itlist = List.begin (); ItList! = List.end ();) { if (Willdelete (*itlist)) { itlist = list.erase (itlist); } else { itlist++; }}
Correct use of Method 2:
Std::list<int> list;std::list<int>::iterator itlist;for (itlist = List.begin (); ItList! = List.end ();) { if (Willdelete (*itlist)) { list.erase (itlist++); } else { itlist++; }}
Error using Method 1:
std::list< int> list;std::list< int>::iterator itlist;for (itlist = List.begin (); ItList! = List.end (); itLis t++) { if (Willdelete (*itlist)) { list.erase (itlist); }}
Error using Method 2:
std::list< int> list;std::list< int>::iterator itlist;for (itlist = List.begin (); ItList! = List.end ();) { if (Willdelete (*itlist)) { itlist = list.erase (++itlist); } else itlist++;}
At the same time to pay attention to the Std::list multithreading is not secure, so multithreading to the list operation is generally to lock, to ensure that the security transfer from: http://blog.csdn.net/iam_charlie/article/details/6062472
Erase () method of list in STL