#include<iostream>
#include<string>
using namespace std;
class A
{
public:
A(int x){rx=x;}
int operator++(){cout<<"++i 先++再返回++後的值\n";rx++;return rx;}
int operator++(int){cout<<"i++ 先取值再++,返回先取的值\n";int i=rx;rx++;return i;}
friend ostream& operator<<(ostream &s,const A c)
{
s<<c.rx;
return s;
}
private:
int rx;
};
int main()
{
A a(4);
cout<<++a<<a++<<endl;
return 0;
}
重載自家運算符的執行次序
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
昔日輝煌不再,PHP老矣,尚能飯否?
原創
2024-05-23 23:48:42
實現“代碼可視化”需要了解的前置知識-編譯器中端
原創
2024-05-21 11:56:05
跨端自渲染繪製的實踐與探索
原創
2024-05-21 11:56:03
數據結構筆記淺記(十四) 樹
原創
2024-05-14 00:28:41
opencvsharp中resize圖像
osc_6mbnx553
2024-05-13 22:07:26
2024 開源之夏|報名 NebulaGraph 項目,領取你的 ¥12,000 獎金
NebulaGraph
2024-05-13 03:51:52
Spring Boot3,啓動時間縮短 10 倍!
原創
2024-05-13 02:20:47
cheerp 編譯器之通用計算模塊ccm1
原創
2024-05-12 21:53:46
雲效 Pipeline as Code 來了!這些場景,用好它效率翻倍!
原創
2024-05-11 21:15:05
「Qt Widget中文示例指南」如何實現一個快捷編輯器(一)
原創
2024-04-30 23:36:29
安全策略增量加速之對象
原創
2024-04-29 22:54:50
數據結構筆記淺記(十二) 雙向隊列
原創
2024-04-18 23:39:23
「Qt Widget中文示例指南」如何實現行編輯功能
原創
2024-04-17 11:37:05
數據結構筆記淺記(九)存儲設備
原創
2024-04-08 23:38:13