以下是一段程序,location类是描述屏幕上一个点的位置,成员函数distance(location&)是计算两个点的距离.
//location.h
#if defined(location_h)
#define location_h
class location {
private:
int x,y;
public:
location(int,int)
int getx(){return x;}
int gety(){return y;}
int distance(location&);
~location();
};
#endif
//location.cpp
#include
location :: location(int m,int n)
{
cout<<"Initializing"<<""< x=m;
y=n;
}
int location :: distance(location&)
{
d=sql(abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2))
}
location :: ~location()
{
cout<<"Destructor for location"<}
void main()
{
location A(-10,20);
location B(-40,60);
}
我的distance(location&)这个成员函数一定有问题,但我实在不知怎么改.请大家多多指教.
--------------------next---------------------
阅读(1207) | 评论(0) | 转发(0) |