#include<iostream>
using namespace std;
struct Point{
int x,y;
Point(int x=0,int y =0):x(x),y(y) {}
};
ostream& operator << (ostream &out, const Point A){
out << A.x << ' ' << A.y<<endl;
return out;
}
Point operator + (const Point& A, const Point& B){
return Point(A.x+B.x,A.y+B.y);
}
int main()
{
Point a, b(1,2);
a.x = 3;
cout << a+b << "\n";
return 0;
}
struct中构造函数写法,重载运算符写法
最新推荐文章于 2024-06-26 01:02:42 发布