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

operator++()和operator++(int)的区别

时间:2016-10-29 19:40:21      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:rem   and   operator   int   const   orm   this   post   tor   

// 前缀形式:增加然后取回值

UPInt& UPInt::operator++()
{
 *this += 1; // 增加
 return *this; // 取回值
}

// postfix form: fetch and increment

const UPInt UPInt::operator++(int)
{
 UPInt oldValue = *this; // 取回值
 ++(*this); // 增加
 return oldValue; // 返回被取回的值
}

operator++()和operator++(int)的区别

标签:rem   and   operator   int   const   orm   this   post   tor   

原文地址:http://www.cnblogs.com/tomcao/p/6011427.html

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