1 #include <iostream>
 2 using namespace std;
 3 
 4 class Tree{
 5 public:
 6     Tree(){
 7         num = 0;
 8     }
 9     void operator ++(){
10         num++;
11     }
12 
13     int num;
14 };
15 
16 int main(){
17 
18     Tree tree;
19     cout<<tree.num<<endl;
20     tree++;
21     cout<<tree.num<<endl;
22 
23     system("pause");
24     return 0;
25 }

上述代码重载了++运算符之后,就可以直接用对象进行++运算了,打印结果如期,分别是0和1

相关文章:

  • 2021-11-17
  • 2021-10-07
  • 2022-01-01
  • 2021-06-30
  • 2021-07-14
猜你喜欢
  • 2021-09-18
  • 2021-12-22
  • 2021-12-07
  • 2022-12-23
  • 2022-01-19
  • 2021-10-12
  • 2021-09-28
相关资源
相似解决方案