I'm working on a project for my school (I'm still a beginner) and I have come across the following problem:
"[Error] no match for 'operator==' (operand types are 'Vehicle' and 'const Vehicle')"
Vehicle
being a class in my project.
This is what is giving me the error:
int DayLog::findWaitingPosistion(Vehicle const& v){
if (find(waitingList.begin(),waitingList.end(),v) != waitingList.end())
return 1;
}
waitingList
is a vector of Vehicle
objects.
I searched and couldn't find an answer even though there were many similar questions to mine I tried everything but nothing worked. Thanks in advance.
The minimum requirements for using find is a specified operator==
function. This is what std::find
uses as it iterates through the vector if it has found your type.
Something like this will be necessary:
class Vehicle {
public:
int number;
// We need the operator== to compare 2 Vehicle types.
bool operator==(const Vehicle &rhs) const {
return rhs.number == number;
}
};
This will allow you to use find. See a live example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With