关于运算符重载的问题
请问Complex operator+(const Complex &x)const与Complex operator+(const Complex x)const的区别
include<iostream.h>
class Complex
{
private:
double real;
double image;
public:
Complex(void):real(0),image(0)
{}
Complex(double rp):real(rp),image(0)
{}
Complex(double rp,double ip):real(rp),image(ip)
{}
~Complex()
{}
Complex operator+(const Complex &x)const;
Complex operator-(const Complex &x)const;
Complex operator*(const Complex &x)const;
Complex operator/(const Complex &x)const;
bool operator==(const Complex &x)const;
Complex& operator+=(const Complex &x);
void Print(void) const;
};
inline Complex Complex::operator+(const Complex &x) const
{
return Complex(real+x.real,image+x.image );
}
inline Complex Complex::operator-(const Complex &x) const
{
return Complex(real-x.real,image-x.image );
}
inline Complex Complex::operator*(const Complex &x) const
{
return Complex(real*x.real,image*x.image );
}
Complex Complex::operator/(const Complex &x)const
{
double m;
m=x.real*x.real+x.image*x.image;
return Complex((real*x.real+image*x.image)/m,(image*x.real-real*x.image)/m);
}
inline bool Complex::operator==(const Complex &x)const
{
return bool(real==x.real &&image==x.image);
}
Complex&Complex::operator+=(const Complex&x)
{
real+=x.real ;
image+=x.image ;
return *this;
}
void Complex::Print(void ) const
{
cout<<"("<<real<<","<<image<<"i)"<<endl;
}