1

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?

user2616744
  • 41
  • 1
  • 7

1 Answers1

1

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.

cpp
  • 3,743
  • 3
  • 24
  • 38