mark i++&++i

STL中

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
// 前缀形式:增加然后取回值

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

// postfix form: fetch and increment

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


STL中对后缀表达式使用了一个临时变量保存了值。效率上来说肯能会低些

内置类型int、byte、等编译器会做优化的,。结果是一样的。可能只有用迭代器是可能要++iter吧。然而C++ 11都是for(auto var : objs)的写法了。所以这种知识知道了并没什么卵用的感觉。

原文地址:https://www.cnblogs.com/leejuen/p/5547445.html