C/C++ 自增自减的前后置语法区分
1) 前置返回一个引用,后置返回一个对象
// ++i实现代码为:
int& operator++(){
*this += 1;
return *this;
}
2) 前置不会产生临时对象,后置必须产生临时对象,临时对象会导致效率降低
//i++实现代码为:
int operator++(int) {
int temp = *this;
++*this;
return temp;
}

浙公网安备 33010602011771号