operator++() 和operator++(int)

#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
posted @ 2014-05-05 19:21  sxcww  阅读(1029)  评论(0编辑  收藏  举报