return complex(a,b)和return (a,b)有什么区别定义一个complex类后 complex complex::operator+(complex c2) return complex(real+c2.real,imag+c2.imag)和return (real+c2.real,imag+c2.imag)为什么有区别?分别输出(6.5,12.5)和(12.5,0

来源:学生作业学帮网 编辑:学帮网 时间:2024/05/13 11:52:54

return complex(a,b)和return (a,b)有什么区别
定义一个complex类后
complex complex::operator+(complex c2)
return complex(real+c2.real,imag+c2.imag)和return (real+c2.real,imag+c2.imag)为什么有区别?分别输出(6.5,12.5)和(12.5,0)

return (a,b)等于return(b),这是逗号运算符的作用,不等于把a,b都返回回去.你可以找教科书上逗号运算符部分好好理解下
只有用return complex(a,b)才能构造合理的complex对象并返回