第12周—阅读程序,写出运行结果。 (1)
2016-05-24 15:32
405 查看
/* 02.2.*Copyright(c) 2016.烟台大学计算机与控制工程学院 03.3.*ALL rights reserved. 04. 4.*文件名称:main.cpp 05. 5.*作者:孙亚茹 06.6.*完成日期:2016年5月24日 07.7.*问题描述:阅读程序,写出运行结果。 08.8.*/ #include <iostream> using namespace std; class Sample { private: int x; public: Sample () { } //1 Sample(int a){x=a;} // 2 void disp(){cout<<"x="<<x<<endl;} //3 friend Sample operator+( Sample &s1, Sample &s2); }; Sample operator+( Sample &s1, Sample &s2) //4 { return Sample(s1.x+s2.x); } int main() { Sample obj1(10); Sample obj2(20); Sample obj3; obj3=obj1+obj2; obj3.disp(); return 0; }
总结:
运算符重载:将运行10+20=30,输出X=30。
相关文章推荐
- 依赖倒置原则
- python3简单实现微信爬虫
- Linux下OpenOffice转换Office为PDF的java实现
- openWrt编译环境搭建及编译
- 关于分支
- JavaScript中判断数据类型的方法总结
- shell中的大括号和小括号 转自“红黑联盟”
- 多态的说明
- 判断输入为正数并且增加千分符
- YangMVC1.2版本-更新日志-文件上传
- 软件架构详解(附图)
- 时间转换成昨天,今天,明天的形式
- Mybatis 多对多表关联
- Android 随机生成4位数 仿验证码
- 保留两位小数
- Struts2与easyui分页查询
- php基于搜索引擎的资源嗅探器
- IOS 处理 GET请求和POST请求
- 怎样让我的MFC程序只能运行一个实例?
- Cordova for iOS-插件开发(二)