小编Ove*_*ker的帖子

为什么在运算符重载时返回允许的构造函数?

为什么在运算符重载时返回允许的构造函数?

这是一个例子:

Complex Complex::operator*( const Complex &operand2 ) const
{
    double Real = (real * operand2.real)-(imaginary * operand2.imaginary);
    double Imaginary = ( real * operand2.imaginary)+(imaginary * operand2.real);

    return Complex ( Real, Imaginary );
}
Run Code Online (Sandbox Code Playgroud)

它似乎是返回对象的构造函数而不是对象本身?什么回到那里?

这似乎更有意义:

Complex Complex::operator*( const Complex &operand2 ) const
{
    double Real = (real * operand2.real)-(imaginary * operand2.imaginary);
    double Imaginary = ( real * operand2.imaginary)+(imaginary * operand2.real);

    Complex somenumber ( Real, Imaginary );

    return somenumber;
}
Run Code Online (Sandbox Code Playgroud)

c++ constructor operator-overloading

5
推荐指数
1
解决办法
144
查看次数

标签 统计

c++ ×1

constructor ×1

operator-overloading ×1