[英]Remove an element of vector using for_each
我有一个班级Student
。 它有一个int
类型的成员nameCoef
。 每个Student
对象都存储在一个 vector 中,它是Group
类的成员。 如果nameCoef == 1
我需要从向量中删除一个对象。 只能通过使用类Student
成员函数getNameCoef()
才能访问nameCoef
。
所以,我试过这个:
struct removeStudent
{
void operator()(const Group &a)
{
group.erase();
}
};
void processGroup()
{
for_each(this->group.begin(), this->group.end(), removeStudent());
}
但我收到一个错误:
非静态成员引用必须相对于特定对象
如何解决?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.