Reputation: 94
I've found a problem while writing code under Visual C++ 2010 Express. When executing last line I get a runtime error "vector iterator not dereferencable". What is wrong with the code below?
vector<int> vec (5, 1001);
vector<int>::iterator begin = vec.begin();
vector<int>::iterator end = vec.begin();
begin++; //std::advance(begin, 1); gives the same result
end++; end++; end++; //std::advance(end, 3); gives the same result
cout << (*begin) << endl;
cout << (*end) << endl;
begin = vec.erase(begin, end);
cout << (*begin) << endl; //It doesn't work
This code works under gcc. When elements are erased one by one it works in VC++ 2010 Express too.
Is it a bug in VC++ 2010 Express?
Upvotes: 3
Views: 214