#include<iostream>
using namespace std;
class Complex
{
private:
double x;
double y;
public:
Comlex()
{
x=0;
y=0;
}
~Complex()
{
}
void SetComplex(double a,double b);
void Add(Complex a,Complex b);
void GetComplex(double &m,double &n);
};
void Complex::SetComplex(double a,double b)
{
x=a;
y=b;
}
void Complex::Add(Complex a,Complex b)
{
x=a.x+b.x ;
y=a.y +b.y ;
}
void Complex::GetComplex(double &m,double &n)
{
m=x;
n=y;
}
int main()
{
Complex x1,x2,x3,x5;
double a=0;
double b=0;
Complex *x4=new Complex();
x1.SetComplex (3.4,5);
x2.SetComplex (2.1,3);
x3.Add (x1,x2);
x3.GetComplex (a,b);
cout<<a<<endl<<b<<endl;
x4->GetComplex (a,b);
cout<<a<<endl<<b<<endl;
x5.GetComplex (a,b);
cout<<a<<endl<<b<<endl;
system("pause");
}
运行结果:
5.5
8
-6.27744e+066
-6.27744e+066
-9.25596e+061
-9.25596e+061
请按任意键继续. . .
为什么不是:
5.5
8
0
0
0
0
?感觉构造函数应该对x,y的值进行初始化啊?