The crash can be reproduced by the below codes.
#include <vector> #include <iostream> using namespace std; int main() { vector<int> tests; tests.push_back(1); tests.erase(tests.rbegin().base()); return 0; } If I use the normal iterator, the erase function call will not casue crash. Does anyone know what the mechanism is? I would apprecaite a explanation.
By the way, the reason I try to use reversely iterator is that deleting an element of vector during reversely iterating does not skip iterating the element after deleted element without additional codes.
tests.rbegin().base() == tests.end(). Thebase()iterator is one position behind where the reverse iterator logically points to. It has to be - there's no position before the first element thatrend().base()could point to otherwise.