c++重载运算符梳理
来源:互联网 发布:o2olr软件下载 编辑:程序博客网 时间:2024/06/13 18:50
c++重载运算符
---by ysmor
重新解释运算符的含义,叫做运算符重载-----c++程序设计P277
不多说了,给代码
#include<iostream>using namespace std;class bign{ public:int x; int y; int z; public: bign(int a,int b,int c) { x=a; y=b; z=c; }//注意用友元函数 friend bign operator + (bign a,bign b);//重定义+ friend bign operator - (bign a,bign b);//重定义- friend bign operator * (bign a,bign b);//重定义* friend bign operator / (bign a,bign b);//重定义/ friend istream & operator >> (istream &in,bign &a);//重定义>> friend ostream & operator << (ostream &out,bign &a);//重定义<<};bign operator + (bign a,bign b){ return bign(a.x+b.x,a.y+b.y,a.z+b.z);}bign operator - (bign a,bign b){ return bign(a.x-b.x,a.y-b.y,a.z-b.z);}bign operator * (bign a,bign b){ return bign(a.x*b.x,a.y*b.y,a.z*b.z);}bign operator / (bign a,bign b){ return bign(a.x/b.x,a.y/b.y,a.z/b.z);}istream & operator >> (istream &in,bign &a){ in>>a.x>>a.y>>a.z; return in;}ostream & operator << (ostream &out,bign &a){ out<<a.x<<" "<<a.y<<" "<<a.z<<endl; return out;}int main() { bign x(0,0,0),y(90,100,908),z(0,0,0); cin>>x; z=x+y; cout<<z<<endl; z=x-y; cout<<z<<endl; z=x*y; cout<<z<<endl; z=y/x; cout<<z<<endl; system("pause"); return 0;}
输入9 100 2
运行结果
99 200 910-81 0 -906810 10000 181610 1 454请按任意键继续. . .
THE END...
欢迎大家跟帖,并继续关注我
1 0
- c++重载运算符梳理
- C++ -- 运算符重载知识梳理
- C++-运算符重载
- [C++]重载运算符
- C#:运算符重载
- c++-++运算符重载
- C++:重载运算符
- 运算符重载(C++)
- [c++]运算符重载
- 【C++】运算符重载
- C++--------------------------------------------运算符重载
- C#:运算符重载
- C++:运算符重载
- C++:运算符重载
- C#:运算符重载
- [C++]运算符重载
- 【c++】运算符重载
- C++:运算符重载
- 踩坑事件:windows操作系统下的eclipse中编写SparkSQL不能从本地读取或者保存parquet文件
- #55 – Application.ShutdownMode
- java数据结构之字符串的模式匹配算法
- 增删改同时获取主键id
- SAS OUTPUT语句
- c++重载运算符梳理
- 反转单向链表
- javascript之模板引擎
- PDO 简介——预处理语句和存储过程
- windows svn搭建a
- win32汇编 多线程编程与事件
- 2016年6月7日 10:42:32
- java实现定时任务 Schedule
- java web 设置持久session