Getting this error while trying to erase the last element of a list. I debugged the code and was able to figure out what causes it and where, here\'s my code:
You need to put ++i in an else clause. The erase function returns the next valid iterator- and you are then incrementing over it, ensuring that you do not iterate over every element. You should only increment it in the case in which you chose not to erase.