<!-- [if gte mso 9]><![endif]--><!-- [if gte mso 9]><![endif]--><!-- [if gte mso 9]><![endif]--><!-- [if gte mso 10]><![endif]-->
STL 有一段代碼
template <class _Tp, class _Alloc>
typename list<_Tp,_Alloc>::iteratorlist<_Tp, _Alloc>::erase(iterator __first,
iterator __last)
{
while (__first != __last)
erase(__first++);
return __last;
}
對erase(__first++)執行步驟的理解:
1. 傳__first參數給erase函數
2. 執行__first++(這時函數erase其它的代碼還沒有執行)
3. 執行erase的其它代碼
測試程序
int g_Postfix = 1;
int g_Prefix = 1;
void post(int k){
printf("post() g_Postfix=%d/n",g_Postfix);
printf("post() ,Parameter value=%d/n",k);
}
void pre(int k){
printf("pre() g_Prefix=%d/n",g_Prefix);
printf("pre() ,Parameter value=%d/n",k);
}
int main(){
post(g_Postfix++);
pre(++g_Prefix);
}