头文件point_dist.h
#include <iostream>
#include <math.h>
using namespace std;
class Point;
class Dist
{
/* private:
Point point3(0,0),point4(0,0); */
/*若加上此处,则会显示 IntelliSense: 应输入类型说明符,为什么?????????????????????????????
??????????????????????????????????*/
public:
void cDist(Point &cPoint1,Point &cPoint2);
};
class Point
{
private:
int x,y;
public:
Point(int CS_x=0,int CS_y=0)
{
x=CS_x;
y=CS_y;
}
Point(Point &p)
{
x=p.x;
y=p.y;
}
void setPoint(int getX,int getY)
{
x=getX;
y=getY;
}
void showPoint()
{
cout<<"横坐标:"<<x<<" 纵坐标:"<<y<<endl;
}
friend void Dist::cDist(Point &cPoint1,Point &cPoint2);
};
源文件mainFunction.cpp
#include "point_dist.h"
void Dist::cDist(Point &cPoint1,Point &cPoint2)
{
double m=pow(double(cPoint1.x-cPoint2.x),2)+pow(double(cPoint1.y-cPoint2.y),2);
cout<<"距离:"<<sqrt(m)<<endl;
}
int main()
{
Point point1(15,45),point2(8,96);
Dist dist;
dist.cDist(point1,point2);
system("pause");
return 0;
}
2.若把Dist类与Point类定义倒过来也有错。。。。。。。。。。
头文件point_dist.h
#include <iostream>
#include <math.h>
using namespace std;
class Dist;
class Point //先定义Point再定义Dist
{
private:
int x,y;
public:
Point(int CS_x=0,int CS_y=0)
{
x=CS_x;
y=CS_y;
}
Point(Point &p)
{
x=p.x;
y=p.y;
}
void setPoint(int getX,int getY)
{
x=getX;
y=getY;
}
void showPoint()
{
cout<<"横坐标:"<<x<<" 纵坐标:"<<y<<endl;
}
friend void Dist::cDist(Point &cPoint1,Point &cPoint2);
};
class Dist
{
public:
void cDist(Point &cPoint1,Point &cPoint2);
};
为什么呢????????????