首页 > 其他 > 详细

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

时间:2016-10-29 19:37:54      阅读:254      评论:0      收藏:0      [点我收藏+]

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

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)的区别

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

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