mercredi 26 août 2015

error using the '==' operator inside lambda when comparing string with method return value

I have a class called Actor that have a instance variable std::string name;
Actor also has a method std::string getName(){return name;}

users is a vector that can have instances of type Account

When trying to compile a method containing the code below

using VA_it = std::vector<Account>::iterator; //vector<Account> iterator
VA_it it = std::find(users.begin(), users.end(), [name](VA_it ac)->bool {return (ac->getName() == name); });   

I get an error:
binary '==': no operator found which takes a left-hand operand of type 'Account' (or there is no acceptable conversion)

Even though the return value of getName() is std::string, so I do not understand why the compiler complains about comparing Account with std::string

My question is: Is it something wrong with the comparision (ac->getName() == name) in a lambda provided that ac->getName() returns a string?

Aucun commentaire:

Enregistrer un commentaire