首先是构造函数,重载
#include <iostream> #include <cstdio> #include <cstring> #include <string> #define maxn 65540 using namespace std; struct Node { int x,y; Node (int x = 0,int y = 0):x(x),y(y) {} //构造函数 }; Node operator + (const Node& a,const Node& b) { return Node(a.x+b.x,a.y+b.y); } ostream& operator << (ostream &out,const Node& p) //重载流输出方式 { out<<"("<<p.x<<","<<p.y<<")"; return out; } int main() { Node a,b(1,2); Node c = a+b; cout<<a+b<<endl;; }