您的位置:首页 > 其它

运算符重载加法(单目)

2016-05-22 19:18 316 查看
/*

*copvriqht(c)2016,烟台大学计算机学院

*All rights reserved.

*文件名称:test.cpp

*作者:陈传祯

*完成日期:2016年5月19日

*版本号:v1.0

*

*问题描述

*输入描述

*程序输出

*/

#include<iostream>

using namespace std;

class Sample

{

private:

int x;

public:

Sample(){}

Sample (int a){x=a;}

void disp(){cout<<"x="<<x<<endl;}

Sample operator+(Sample &s);

};

Sample Sample::operator+(Sample &s)

{

return Sample(x+s.x);

}

int main()

{

Sample t1(10);

Sample t2(30);

Sample t3;

t3=t1+t2;

t3.disp();

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: