级联重载+运算符

use*_*511 2 c++ operator-overloading

这是当前的代码:

const complex complex::operator+(const complex &right)
{
     complex result;
     result.realPart = realPart + right.realPart;
     result.imPart = imPart + right.imPart;
     return result;
}
Run Code Online (Sandbox Code Playgroud)

我该如何修改呢

a = b + c + d;

被允许?

Mar*_*tos 5

使它成为const成员函数:

const complex complex::operator+(const complex &right) const ...
Run Code Online (Sandbox Code Playgroud)