I have faced with a strange runtime error for the following code:
#include <algorithm>
#include <vector>
using std::vector;
struct Data
{
int id;
};
int main()
{
vector<Data> mylist;
Data m;
m.id = 10;
mylist.push_back(m);
mylist.erase(std::remove_if(
mylist.begin(),
mylist.end(),
[](const Data &m) {
return m.id>100;
}));
return 0;
}
The error says:
Vector erase iterator outside range
I am not after solving the problem like Ref1, Ref2 but realizing the cause of the problem and whether I have done something wrong.