Serge
Serge

Reputation: 15

Overloaded operator has too many parameters, visual studio c++

I'm trying to declare an overload, non-friend, non-member ' - - operator in a header file:

 Quad operator-(const Quad &qu1, const Quad &qu2); 

But I am getting:

 "error C2804: binary 'operator -' has too many parameters" 

This code is right from the book and problem statement and I cannot seem to resolve it. Thanks for your help.

Upvotes: 1

Views: 1140

Answers (1)

Michael Nastenko
Michael Nastenko

Reputation: 3103

Binary operators in class definition scope must take only one argument.

Quad operator-(const Quad &quRight)
{
    Quad res;
    res.x = this->x - quRight.x;
    // all other components
    // ...
   return res;
}

Or you can move operator overloading outside of class.

Upvotes: 1

Related Questions