编程小练习
2016-05-17 17:10
316 查看
#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+(const Sample &s); //成员函数
};
Sample Sample:: operator+(const Sample &s)//运算符+的重载
{
return Sample(x+s.x);
}
int main()
{
Sample obj1(20);
Sample obj2(20);
Sample obj3;
obj3=obj1+obj2;
obj3.disp();
return 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+(const Sample &s); //成员函数
};
Sample Sample:: operator+(const Sample &s)//运算符+的重载
{
return Sample(x+s.x);
}
int main()
{
Sample obj1(20);
Sample obj2(20);
Sample obj3;
obj3=obj1+obj2;
obj3.disp();
return 0;
}
相关文章推荐
- SpringMVC4零配置--web.xml
- selenium-python-常用方法集锦(不断补充)
- 使用python来格式化显示windows错误码
- Java环境设置
- 完美解决phpdoc导出文档中@package的warning及Error的错误
- Python转义字符空格字符
- YII学习总结3(session)
- C#向无窗口的进程发送消息
- springMVC -- 整合UEditor(富文本编辑器)
- java中DatagramSocket连续发送多个数据报包时产生丢包现象解决方案
- 第十七章 springboot + devtools(热部署)
- 编程小练习
- 中国工程师如何获 Google 的工作机会?
- java Gzip 压缩与解压缩
- Java中堆和栈的区别
- javaweb数据库的连接
- github常用命令
- 编译 lua
- POJ 3254 Corn Fields(状态压缩DP)
- myeclipse工程当中的.classpath 和.project文件什么作用?