#include <iostream>
using namespace std;
class A{
public:
    int a;
public:
    A& operator++(){
        cout<<"A& operator++()"<<endl;
        a=a+1;
        return *this;
    }
    A operator++(int){
        cout<<"A operator++(int)"<<endl;
        A b=*this;
        a=a+1;
        return  b;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
    A test;
    test.a=12;
    test++;
    ++test;
    cout<<test.a<<endl;
    system("pause");
}

运行结果:

A operator++(int)
A& operator++()
14

相关文章:

  • 2022-01-27
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
  • 2021-05-17
猜你喜欢
  • 2021-09-06
  • 2022-02-23
  • 2022-12-23
  • 2022-02-15
  • 2022-01-02
  • 2022-12-23
  • 2022-01-08
相关资源
相似解决方案