I thought that in
cout << "Hello world"
cout object has an operator overloading so we can pass strings into cout objects member function.
But in some example code I saw a class which has an operator overloading defined in it.
class GenericPlayer : public Hand
{
..
friend ostream& operator <<(ostream& os, const GenericPlayer& aGenericPlayer);
..
};
...
cout << aGenericPlayer << endl;
...
Even if it is not, what if both cout and aGenericPlayer overload operator<< ?
std::coutis anstd::ostreamobject, so anystd::ostream& operator<<(std::ostream, SomeType)will work withstd::cout. But the point is that the second parameter of the operator is different, so the overloads are different. The first “string” one is something likeand the second
So, they are different operator overloads and there is no ambiguity.