我正在尝试在头文件中声明一个重载,非朋友,非成员' - - 运算符:
Quad operator-(const Quad &qu1, const Quad &qu2);
但我得到了:
"error C2804: binary 'operator -' has too many parameters"
这段代码是正确的书和问题陈述,我似乎无法解决它。谢谢你的帮助。
答案 0 :(得分:1)
类定义范围中的二元运算符必须只包含一个参数。
Quad operator-(const Quad &quRight)
{
Quad res;
res.x = this->x - quRight.x;
// all other components
// ...
return res;
}
或者你可以在课堂外移动操作符重载。