++i是在i上直接加1,++i的值是i本身
i++也是在i上加1,i++的值是加1前的i
具体实现如下:
++i:前置返回一个引用
// ++i实现代码为:
int& operator++()
{
*this += 1;
return *this;
}
i++:后置必须产一个临时对象,而临时对象会导致效率降低
//i++实现代码为:
int operator++(int)
{
int temp = *this;
++*this;
return temp;
}