码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-05-07 18:37:55      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   color   

bubuko.com,布布扣
#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");
}
bubuko.com,布布扣

运行结果:

bubuko.com,布布扣
A operator++(int)
A& operator++()
14
bubuko.com,布布扣

operator++() 和operator++(int),布布扣,bubuko.com

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

标签:style   blog   class   code   java   color   

原文地址:http://www.cnblogs.com/sklww/p/3709883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!