运算符重载加法(单目)
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;
}
*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;
}
相关文章推荐
- 单链表排序(冒泡排序法)
- EXPORT_SYMBOL
- ArcGIS Engine开发中利用GP工具时常出现的错误
- JSP9大内置对象及方法
- Android开发之Fragment的生命周期
- mysql基本操作
- spring整合技术之---利用JDBC访问数据库
- 运算符重载加法(双目)
- Nginx日志分割脚本
- Ruby中的变量定义
- NetBeans8.1开发Spring MVC的基础代码
- poj 3070 Fibonacci(矩阵加速DP)
- Leetcode--Flatten Binary Tree to Linked List
- shader内置函数
- 学习进度条
- JavaScript 基础(七) 箭头函数 generator Date JSON
- 2016百度之星总结帖
- 安卓屏幕最大化
- 安卓屏幕最大化
- SSD中没有efi分区的解决办法即固态硬盘不能设置uefi引导的解决办法