&c 和 c 请看红字部分
class Complex{
private :
float Real, Image;
public:
Complex(float x = 0, float y = 0)
{
Real = x;
Image = y;
}
void Show(int i)
{
cout << "c" << i << "=" << Real << "+" << Image << "i" << endl;
}
Complex operator + (Complex c);//////////////////////////请问这里书籍上给的是&c 但是这里用c结果一样
Complex operator - (Complex &c);/////////////////////////为什么要用&c
void operator += (Complex &c);
void operator = (Complex &c);
};
Complex Complex :: operator + (Complex c)///////////////////
{
Complex t;
t.Real = Real + c.Real;
t.Image = Image + c.Image;
return t;
}
Complex Complex :: operator -(Complex &c)/////////////////////////
{
Complex t;
t.Real = Real - c.Real;
t.Image = Image - c.Image;
return t;
}
void Complex :: operator += (Complex &c)
{
Real = Real + c.Real;
Image = Image + c.Image;
}
void Complex :: operator = (Complex &c)
{
Real = c.Real;
Image = c.Image;
}
void main()
{
Complex c1(15,34), c2(30,57),c3,c4;
c1.Show(1);
c2.Show(2);
c3 = c1 + c2;
c4 = c1 - c2;
c3.Show(3);
c4.Show(4);
c2 += c1;
c2.Show(5);
}