这是当前的代码:
const complex complex::operator+(const complex &right)
{
complex result;
result.realPart = realPart + right.realPart;
result.imPart = imPart + right.imPart;
return result;
}
我如何修改
a = b + c + d;
是允许的吗?
答案 0 :(得分:5)
使其成为const成员函数:
const complex complex::operator+(const complex &right) const ...