-
++i 和 i++的区别
++i先自增1,再返回,i++先返回i,再自增1
-
++i 和 i++的实现
【++i 的实现】:
int& int::operator++() { *this +=1; return *this; }
【i++ 的实现】:
const int int::operator(int) { int oldValue = *this; ++(*this); return oldValue; }
++i先自增1,再返回,i++先返回i,再自增1
【++i 的实现】:
int& int::operator++() { *this +=1; return *this; }
【i++ 的实现】:
const int int::operator(int) { int oldValue = *this; ++(*this); return oldValue; }