首页 > 编程语言 > 详细

竞赛中常用的C++写法

时间:2014-10-20 15:06:09      阅读:230      评论:0      收藏:0      [点我收藏+]

首先是构造函数,重载

#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;;
}


竞赛中常用的C++写法

原文:http://blog.csdn.net/y990041769/article/details/40300597

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!