首页 > 其他 > 详细

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

时间:2014-05-07 18:37:01      阅读:577      评论:0      收藏:0      [点我收藏+]
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)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!