当前位置:网站首页>前置后置运算符重载
前置后置运算符重载
2022-08-09 14:59:00 【李昊19961128】
#include<iostream>
using namespace std;
//重载递增运算符
//自定义整型
class MyInteger
{
friend ostream& operator<<(ostream& cout, MyInteger myint);
public:
MyInteger()
{
m_Num = 0;
}
//重载前置++运算符 返回引用为了一直对一个数据进行递增操作
MyInteger& operator++()
{
//先进行++运算
m_Num++;
//再将自身做返回
return *this;
}
//重载后置++运算符
//void operator++(int) int代表占位参数,可以用于区分前置和后置递增
MyInteger operator++(int)
{
//先 记录当时结果
MyInteger temp = *this;
//后 递增
m_Num++;
//最后将记录结果做返回
return temp;
}
private:
int m_Num;
};
//重载<<运算符
ostream& operator<<(ostream& cout, MyInteger myint)
{
cout << myint.m_Num;
return cout;
}
void test01()
{
MyInteger myint;
cout << ++(++myint) << endl;
cout << myint << endl;
}
void test02()
{
MyInteger myint;
cout << myint++ << endl;
cout << myint << endl;
}
int main() {
//test01();
test02();
//int a = 0;
//cout << ++(++a) << endl;
//cout << a << endl;
system("pause");
return 0;
}
边栏推荐
- hugging face tutorial - Chinese translation - preprocessing
- Postgraduate Work Weekly (Week 6)
- 时间序列分析
- 【力扣】593. 有效的正方形
- Stetman读peper小记:Defense-Resistant Backdoor Attacks Against DeepNeural Networks in Outsourced Cloud
- R-CNN Fast R-CNN Faster R-CNN总结
- [Paper reading] LIME: Low-light Image Enhancement via Illumination Map Estimation (the most complete notes)
- 【工具使用】Modscan32软件使用详解
- 交叉编译 OpenSSL
- Monte Carlo simulation
猜你喜欢

【Postgraduate Work Weekly】(Week 8)

流体拓扑优化问题

使用NATS及其nats.c客户端简单示例用法(nats.c的API接口)

MNIST数据集的训练(内附完整代码及其注释)

NiN(Network in Network) pytorch实现

永磁同步电机电位器调速及数码管实时显示

Stetman读paper小记:Backdoor Learning: A Survey(Yiming Li, Yong Jiang, Zhifeng Li, Shu-Tao Xia)

堆(heap)系列_0x04:堆的内部结构(_HEAP=_HEAP_SEGMENT+_HEAP_ENTRY)

堆(heap)系列_0x05:一张图剖析堆块分配和FreeLists的联系

Vim实用技巧_3.可视模式和命令模式
随机推荐
【力扣】593. 有效的正方形
Vim实用技巧_0.vim - introduction
解决pyqt5 DLL load failed: 找不到指定的程序的问题
【深度学习】原始问题和对偶问题(六)
【力扣】617. 合并二叉树
深入浅出最优化(4) 拟牛顿法
Postgraduate Work Weekly (Week 6)
Vim practical skills_4. Manage multiple files (open + split + save + netrw)
【工具使用】Modbus Poll软件使用详解
用广搜和动态规划写个路径规划程序
Heap series _0x03: heap block + malloc/new bottom layer + LFH (WinDbg analysis)
【知识分享】Modbus通信协议详解
Markdown 文档生成 PDF
Vim实用技巧_8.替换(substitute)和global命令
"Deep learning" evaluation index of target detection
UDP 基本通信框架
堆(heap)系列_0x02:堆的前世今生(WinDbg+Visual Studio汇编)
深入浅出最优化(3) 最速下降法与牛顿法
多元回归分析
Gray Relevance Matrix——Application of MATLAB in Mathematical Modeling