按教程上的写了个类组合小程序,在编译的时候通不过了,请教各位,是哪里错了呢?要怎么改?
程序如下:
#include<iostream>
#include<math.h>
using namespace std;
class Poing
{private:
float x,y;//点的坐标
public:
Point(float xx,float yy)
{cout<<"point构造函数"<<endl;
x=xx;y=yy;
}
Point(Point &p)
{x=p.x;y=p.y;
cout<<"Point拷贝构造函数"<<endl;
}
float GetX(void){return x;}
float GetY(void){return y;}
};
class Distance
{
private:
Point p1,p2;
double dist;
public:
Distance(Point a,Point b);
double GetDis(void){return dist;};
}
Distance::Distance(Point a,Point b):p1(a),p2(b)
{cout<<"Distance构造函数"<<endl;
double x=double(p1.GetX()-p2.GetX());
double y=double(p1.GetY()-p2.GetY());
dist=sqrt(x*x+y*y);
}
void main()
{
Point myp1(1,1),myp2(4,5);
Distance myd(myp1,myp2);
cout<<"the distance is:";
cout<<myd.GetDis()<<endl;
}
就是这个小程序啦:)
会的朋友一定帮忙哟,请你喝酒