我正在为我的学校设计一个项目(我仍然是初学者),但是遇到了以下问题:
"[Error] no match for 'operator==' (operand types are 'Vehicle' and 'const Vehicle')"
Vehicle
在我的项目中上课。
这就是给我错误的原因:
int DayLog::findWaitingPosistion(Vehicle const& v){
if (find(waitingList.begin(),waitingList.end(),v) != waitingList.end())
return 1;
}
waitingList
是Vehicle
对象的向量。
我进行了搜索,但找不到答案,尽管我遇到了许多类似的问题,但我尝试了所有方法,但无济于事。提前致谢。
使用find的最低要求是指定的operator==
功能。std::find
如果找到了类型,这就是在向量中进行迭代的用途。
这样的事情将是必要的:
class Vehicle {
public:
int number;
// We need the operator== to compare 2 Vehicle types.
bool operator==(const Vehicle &rhs) const {
return rhs.number == number;
}
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句