哈尔滨工程大学课件
运算符重载
运算符重载
—
—
实例
实例
复数的运算
复数的运算
class complex
class complex
{
{
public:
public:
complex(double r=0.0,double i=0.0)
complex(double r=0.0,double i=0.0)
{ real=r; imag=i; }
{ real=r; imag=i; }
void display()
void display()
{cout<<real<<“,”<<imag<<endl;}
{cout<<real<<“,”<<imag<<endl;}
private:
private:
double real;
double real;
double imag;
double imag;
};
};