Following is the class and container
class student {
std::string name;
int id;
}
set<Student*, compare> s; // sorted by id that i have done correctly
class compare {
public:
bool operator()( Student* s1, Student* s2) {
return s1->id < s2->id;
}
};
How to remove a object from set having some name = "suri";
What I did?
std::remove(s.begin(), s.end(), nameIs("suri"));
functor is
struct nameIs {
nameIs ( std::string s ) : toFind(s) { }
bool operator() ( Student* st)
{ return st->name.compare(toFind) == 0; }
std::string toFind;
};
But I am getting compile time error Error 2 error C3892: '_Next' : you cannot assign to a variable that is const c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 1816
What wrong am i doing? How to remove a customized object using stl remove from container set?