I am trying to use the “find” function here. For that here’s the code for the ‘==’ operator. But I am getting a “too many parameters for this operator function” error at the word “operator”.
Can anyone kindly help me out ? Thanks.
struct gr_log
{
string name;
string category;
string description;
float cost;
bool operator==(const gr_log& l, const gr_log& r) const
{
return l.name == r.name;
}
};
And:
vector<gr_log>::iterator it;
it = find (grocery.begin(), grocery.end(), "Sugar");
A member operator only takes one argument:
Alternatively, you could write a
friendoperator:Also, you’ll need to perform a
findusing an instance of gr_log because you can’t compare a gr_log with a string like you’re trying to do: