Reputation: 41
In my text book they give an example of overloading the + operator
Sales_item operator+ (const Sales_item& lhs, const Sales_item& rhs)
{
Sales_item ret(lhs);
ret += rhs;
return ret;
}
But when I try it for my linked list, it tells me it can only take zero or one argument.
What is it that I'm not seeing and how would you even add 2 objects if you can't take 2 arguments?
Upvotes: 1
Views: 80
Reputation: 3801
If your operartor+ is a member function it doesn't need two arguments, as the object of the class you call operator+ on is the left-hand side argument. But you have already such an operator: operator+=. As it was suggested by chris and nims move operator+ outside Sales_item class.
Upvotes: 1