#include <iostream>
#include <math.h>
using namespace std;
class Point {
private:
float x;
float y;
public:
Point(float X = 0.0f, float Y = 0.0f) :x(X), y(Y) {
};
float show();
friend Point operator -(Point& t, Point& t1);
};
float Point::show() {
cout << x << "," << y << endl;
return 0;
}
Point operator +(Point& t, Point& t1) {
return sqrt((t.x - t1.x) * (t.x - t1.x) + (t.y - t1.y) * (t.x - t1.y));
}
int main() {
Point t, t1(3, 4), t3;
t.show();
t3 = t - t1;
cout << t3.show() << endl;
}
题目要求
(1)编写构造函数,用于完成点类对象初始化。默认初始值为(0,0)。
(2)编写成员函数show(),用于显示平面点的坐标值。
(3)重载减法运算符为非成员函数,用于计算当前点与另一点之间的距离计算。
(4)编写main()函数完成上述类的测试应用。
vs2019错误报告,不知道错在哪里