参数++

    技术2025-11-15  9

    <!-- [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);

    }

    最新回复(0)