Why does this code give the error message "IntelliSense: too many parameters for this operator function"
int operator+(PerfectNum a,PerfectNum b)
{
return (a.thenum+b.thenum);
}
PerfectNum is a regular class, and thenum is an int. This method is in the class.
You're defining this as a member function, right?
In that case, the left hand side is simply *this:
// .h
class PerfectNum
{
public:
int operator+(PerfectNum other) const;
};
// .cpp
int PerfectNum::operator+(const PerfectNum &other) const
{
return this->thenum + other.thenum;
}
You need to make your operator a non-member function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With