级联重载+运算符

时间:2010-07-17 06:25:49

标签: c++ operator-overloading

这是当前的代码:

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;

是允许的吗?

1 个答案:

答案 0 :(得分:5)

使其成为const成员函数:

const complex complex::operator+(const complex &right) const ...