关于结构体,重载等

1、结构体的初始化(两种方法)

 1 struct node{
 2     int x,y;
 3     node (int x=1,int y=2) {
 4         this->x=x;
 5         this->y=y;
 6     }
 7 };
 8 
 9 struct node{
10     int x,y;
11     node (int x=1,int y=2) :x(x),y(y) {}
12 };

有一个发现,对于用到 stack <node> S; S.push(1,2)这样的操作只有结构体有构造函数才可以这样用,否则会报错

2、关于运算符的重载

1 node operator +(const node&a,const node&b)
2 {
3     return node(a.x+b.x,a.y+b.y);
4 }

其它的运算符重载操作类似

3、关于读写的重定向

1 freopen("a.txt","r",stdin);
2 freopen("b.txt","w",stdout);

猜你喜欢

转载自www.cnblogs.com/Msmw/p/10617518.html