The insert operator (<<) can be used as a member function or as a friend function.
operator <is used as a member function
ostream& operator<<(ostream& os);
This function should be called as:
dom << cout;
In general, if you use an operator as a member function, the left side of the operator should be an object. This object is then implicitly passed as an argument to the member function. But the challenge confuses the user, and he does not look very good.
operator <is used as a function of a friend
friend ostream& operator<<(ostream& os, const Domino& obj);
This function should be called as:
cout << dom;
In this case, the dom object is explicitly passed as a reference. This call is more traditional, and the user can easily understand the meaning of the code.
source share