结构体、运算符重载


#include <bits/stdc++.h>
#define _for(i, a, b) for (int i = (a); i < (b);++i)
#define _rep(i, a, b) for (int i = (a); i <= (b);++i)
using namespace std;
struct Point{
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y){};
};
Point operator+(const Point A, const Point B)
{
    return Point(A.x + B.x, A.y + B.y);
}
ostream& operator<<(ostream& out,const Point&p){      //引用out
    out << "(" << p.x << "," << p.y << ")" << endl;
    return out;
}
int n, l;

int main()
{
    Point A, B(2, 3);
    cout << A + B << endl;
    A.x=10;
    cout << A + B << endl;
    return 0;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM