#include using namespace std; class Point;//先声明类型Point int horizontalDistance(const Point& first, const Point& second);//水平距离函数声明 int verticalDistance(const Point& first, const Point& second);//垂直距离函数声明 class Point { private: int x;//横坐标 int y;//纵坐标 public: Point(int x=0, int y = 0)//构造函数 { this->x = x; this->y = y; } friend int horizontalDistance(const Point& first, const Point& second); friend int verticalDistance(const Point& first, const Point& second); }; //水平距离函数定义 int horizontalDistance(const Point& first, const Point& second) { if(first.x -second.x >=0) return first.x-second.x; else return second.x-first.x; } //垂直距离函数定义 int verticalDistance(const Point& first, const Point& second) { if(first.y -second.y >=0) return first.y-second.y; else return second.y-first.y; } //测试 int main() { Point a(1,2);//定义三个Point对象 Point b(0,0); Point c(-1,-1); //测试 cout<< horizontalDistance(a,b) <