以下是类和容器
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;
}
};
如何从具有某些名称 =“suri”的集合中删除对象;
我做了什么?
std::remove(s.begin(), s.end(), nameIs("suri"));
函子是
struct nameIs {
nameIs ( std::string s ) : toFind(s) { }
bool operator() ( Student* st)
{ return st->name.compare(toFind) == 0; }
std::string toFind;
};
但我收到编译时错误 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
我在做什么错?如何使用 stl remove 从容器集中删除自定义对象?