构造函数
#include <iostream>
struct Point{ //构造点
int x;
int y;
Point(int _x = 1, int _y = 1){
this->x = _x; // this 代表一个临时指针,通俗地说谁调用它,它就指向谁
this->y = _y;
}
Point(const Point &point){
this->x = point.x;
(*this).y = point.y;
}
Point operator+(Point point){
point.x += (*this).x;
point.y += this->y;
return point;
}
struct Line{ //构造一个线
Point point1, point2;
Line(Point point_1, Point point_2){
this->point1 = point_1;
this->point2 = point_2;
}
};
void swap(){ //交换一个点的x值与y值
int t = this->x;
this->x = (*this).y;
this->y = t;
return;
}
};
int main(){
Point point1;
Point point2(5);
Point point3(-2, 5);
Point point4 = point2;
Point point5 = point1 + point3;
printf("point5:(%d %d)\n", point5.x, point5.y);
point5.swap();
printf("point1:(%d %d)\n", point1.x, point1.y);
printf("point2:(%d %d)\n", point2.x, point2.y);
printf("point3:(%d %d)\n", point3.x, point3.y);
printf("point4:(%d %d)\n", point4.x, point4.y);
printf("point5:(%d %d)\n", point5.x, point5.y);
return 0;
}