Reputation: 1
I am trying to overload an operator <<
in a class I created which compares two strings no matter the casing. Here is my bool operator
friend bool operator <<(const string& member, const string& player) {
return toLowerCase(member) == toLowerCase(player);
}
The program returns an error at this point in my code
current->name << member
Now current is a pointer to a node which contains a string name and member is a string that is passed by reference when the user is prompted. The error I get is
invalid operands to binary expression('string'(aka'basic_string<char>') and 'string')
Upvotes: 0
Views: 119
Reputation: 56479
Move that declaration out of your class and remove friend
keyword:
bool operator <<(const string& member, const string& player)
{
return toLowerCase(member) == toLowerCase(player);
}
Upvotes: 0
Reputation: 16824
The error message suggests it's not picking up your overload, but trying to use the built-in bitshift operator on string
s (and failing, of course). I'm not sure why, given the information you've supplied.
Anyway, a much better idea would be to use a non-member, non-operator compare()
function -- using operator<<
to compare strings is just going to confuse the hell out of anybody looking at your code (even you, in a couple of years time).
Upvotes: 1