我试图重载==操作符,然后用主函数中的代码对其进行测试。它给了我一个错误,并说我的if语句中的z必须是bool类型或转换为一个。我只是想知道我在哪里出了问题,怎么去设置这个部分。这是代码片段。我宣布双重真实&作为私有变量也是双重想象。C++ Overloading ==复数
Complex Complex::operator==(const Complex &operand2) const
{
if (real == operand2.real, imaginary == operand2.imaginary)
return true;
else
return false;
}
int main()
{
Complex x(1, 2);
Complex y(2, 3);
Complex z, w, v;
z = x + y;
w = x – y;
if (z == w)
cout << " z = w" << endl;
else
cout << " z != w" << endl;
return 0;
}
嗯是一个愚蠢的错误,完全滑倒在返回类型的我的头脑,谢谢! – John