C++ : List iterator not incrementable

后端 未结 3 873
抹茶落季
抹茶落季 2020-12-10 18:41

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:



        
3条回答
  •  盖世英雄少女心
    2020-12-10 19:39

    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.

提交回复
热议问题