overloaded 'operator+' must be a unary or binary operator error
You want to do either:
// Member function, performs (*this + right)
Point operator+ (Point & right)
or
// Free function, performs (left + right)
Point operator+ (const Point &left, const Point& right)
You made the operator a member function, meaning it actually has three parameters when you include the implicit first this
parameter.
Either:
- Use
*this
rather thanp1
and get rid of that first parameter, or - Make the operator overload a free function (instead of a member) — this is preferred.
It sounds like you have declared your operator as a member function. A member function takes an implicit first parameter, meaning your operator now takes three parameters. You can fix this by making it a non-member function.
In any case, it is preferable to declare it as a non-member, to ensure symmetry between the LHS and the RHS of the operation.
As for std::move
, it is in the <utility>
header. Although I can't see the reason to use it here.