Complex operator +( Complex &, Complex &) 与Complex operator +( Complex , Complex )区别和联系#includeclass Complex{public:Complex(){real=0;imag=0;}Complex( double r){real=r;imag=0;

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 12:16:34
Complex operator +( Complex &, Complex &) 与Complex operator +( Complex , Complex )区别和联系#includeclass Complex{public:Complex(){real=0;imag=0;}Complex( double r){real=r;imag=0;
xTok@~876j}OlSX66uud*IZYŪ%_awg7;sw=ܓCc'0U$[qDmiwWMIT;m{~^̪. Ѭkfq]הߏ#X v'VچxVAT1 u}"bݘsK8[03qPi ܫ/#f)CL@M[GHSYp^]u+D^ĦeAV+TGLmʖ;zRa&oRHWe@]M*uwM;> $<~EU\7 Q]ap/Nu+n*F`-uLtT6`!$txPv_v9{騖za^/;>0H(,,qI `OK CԏW*匧Vf&P'I됼o]z)q25޽5nA~-xW9%S}s?ri>ܸ!Ms"FOH9G9`v#$Ra

Complex operator +( Complex &, Complex &) 与Complex operator +( Complex , Complex )区别和联系#includeclass Complex{public:Complex(){real=0;imag=0;}Complex( double r){real=r;imag=0;
Complex operator +( Complex &, Complex &) 与Complex operator +( Complex , Complex )区别和联系
#include
class Complex{
public:
Complex()
{
real=0;
imag=0;
}
Complex( double r)
{
real=r;
imag=0;
}
Complex(double r, double i):real(r),imag(i) {}
friend Complex operator + ( Complex & , Complex & );
void display();
private:
double real;
double imag;
};
Complex operator +( Complex &k, Complex &t) //这里用这个不对,但用Complex operator +( Complex //k, Complex t) 是对的.或者用Complex operator +( //const Complex &k, const Complex &t) 也是对的(下// 面///函数定义一起修改就行).说说这三种区别和联系
{
return Complex(k.real+t.real, k.imag+t.imag);
}
void Complex::display()
{
cout

Complex operator +( Complex &, Complex &) 与Complex operator +( Complex , Complex )区别和联系#includeclass Complex{public:Complex(){real=0;imag=0;}Complex( double r){real=r;imag=0;
问题在于这句:
c3=c2+6.5;
6.5被自动转成临时对象,而临时对象是const类型的,可以参数这个文章 :