This指针

来源:百度文库 编辑:神马文学网 时间:2024/04/30 17:20:10

 

14.This指针

#include

 

class CComplex

{

private:

       double real;

       double imaginary;

public:

       void Set(double r,double i);

       CComplex Add(CComplex c);

       void Show();

};

 

void CComplex::Set(double r,double i)

{

       real=r;

       imaginary=i;

}

 

CComplex CComplex::Add(CComplex c)

{

       CComplex temp;

       temp.real=this->real+c.real;

       temp.imaginary=this->imaginary+c.imaginary;

       return temp;

}

 

void CComplex::Show()

{

       cout<

}

 

void main()

{

       CComplex ob1,ob2,sum;

       ob1.Set(1,3.5);

       ob2.Set(10.5,4);

       sum=ob1.Add(ob2);

       sum.Show();

}

运行结果如图: