c++复习之重载运算符
来源:互联网 发布:大智慧 股票数据接口 编辑:程序博客网 时间:2024/05/21 14:40
c++复习之重载运算符
重载运算符是c++实现多态的方法之一(另外是虚函数动态绑定和函数名重载),需要好好掌握。
/* * Author: ktmzgl * Created Time: 2017/3/4 16:27:02 * File Name: F:\Vim\code\Tryoperator.cpp */#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <string>#include <vector>#include <stack>#include <queue>#include <set>#include <time.h>using namespace std;const int maxint = -1u>>1;class Try{ public: int a; string s; Try(){} Try(int aa,string ss):a(aa),s(ss){} friend istream & operator >>(istream & in , Try &t); friend ostream & operator <<(ostream & out,Try &t); Try operator +(const Try &t){ return Try(a+t.a,s+t.s);} friend bool operator <(Try &t1,Try &t2) ;};istream & operator >>(istream & in , Try &t) { in>>t.a>>t.s; return in;}ostream & operator <<(ostream & out,Try &t){ out<<t.a<<" "<<t.s<<endl;}bool operator <(Try &t1,Try &t2){ return t1.a<t2.a;}int main(){ Try tmp; cin>>tmp; cout<<tmp; Try tmp1(2,"ff"); Try tmp2=tmp+tmp1; cout<<tmp2; if(tmp<tmp2) cout<<"tmp小于tmp2"<<endl; return 0;}
0 0
- C++理论复习之运算符重载
- c++复习之重载运算符
- 【C++】C++大数之运算符重载
- 【C++】之【运算符重载函数】
- C语言之重载运算符()/[]/++/->等运算符
- C++-运算符重载
- [C++]重载运算符
- C#:运算符重载
- c++-++运算符重载
- C++:重载运算符
- 运算符重载(C++)
- [c++]运算符重载
- 【C++】运算符重载
- C++--------------------------------------------运算符重载
- C#:运算符重载
- C++:运算符重载
- C++:运算符重载
- C#:运算符重载
- 浅谈jQuery.extend 与 jQuery.fn.extend
- Leetcode Algorithm 215. Kth Largest Element in an Array
- 最粗暴的opencv-python-linux安装
- 正式入住CSDN博客
- 动态规划(4)滑雪问题
- c++复习之重载运算符
- PHP匿点之数组运算符+和array_merge区别
- 算法笔记_062-蓝桥杯练习 最小乘积(基本型)(Java)
- Java设计模式——Comparable接口&&Comparator(CC系)策略模式的应用
- 你若读书 风雅自来
- 题目1021:统计字符
- 浅谈 JavaScript 模块化编程
- UVA-133 The Dole Queue
- 开源APP项目源码分析(5)- 音乐播放器类