码迷,mamicode.com
首页 > 编程语言 > 详细

笔记:C++重载++前后区分

时间:2017-09-07 20:27:44      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:bsp   turn   tmp   eth   this   return   ret   参数   返回值   

a++

++a

++有2种方式,那么在重载++的时候要怎么区分:

前置:

T& operator++(){

    do something

    return *this;

}

后置:

const T operator++(int){

    T tmp = *this;

    ++(*this);

    return tmp;

}

 

区别主要在:

1.返回值

2.函数参数

 

 

笔记:C++重载++前后区分

标签:bsp   turn   tmp   eth   this   return   ret   参数   返回值   

原文地址:http://www.cnblogs.com/-maybe/p/7491485.html

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