How to avoid iterator invalid post erase in a function
Refer below code : It just demonstrate add to list and erase from list... Write now code works as it is of int and I have updated iterator in statement related to the erase Assume that below four lines are in a seperate function: if (*itrA == 5 && *itrB == 3) myList.push_back(15); if (*itrA == 5 && *itrB == 10) itrB = myList.erase(itrB); And also assume that iterator is pointing to class pointer instead of int... Itra and itrb is assigned to a local pointer variable and passed those variables to function which push_backs and erases... How to avoid iterator invalid now in function ? Feel free to ask for queries. If it is not clear, let me know and will create a full scenario in sample code https://code.sololearn.com/cCVaR6OkyIeg/?ref=app