c ++ ++ i and the difference between the i ++

Write ++i, ++jcompared to write i++, j++execution speed of the program faster. Recalling ++the example is overloaded into front and rear operator as follows:

:: CDemo CDemo operator ++ () 
{   // front ++ 
    ++ n-;
     return * the this ; 
} 
CDemo CDemo :: operator ++ ( int K) 
{   // rear ++ 
    CDemo tmp (* the this );   // record the object before modification 
    n-++ ;
     return tmp;   // returns the object before modification 
}

Post ++to generate a plurality of partial objects tmp, thus it performs slower than upstream. Similarly, the iterator is an object, the STL  the overloads of the ++operator is used, slower than the rear pre-forms may also form. In many cycles in ++iand i++it might cause considerable running time differences. Therefore, this tutorial specifically mentioned in front of the loop control variable i, to develop writing ++i, not writing i++habits.

Guess you like

Origin www.cnblogs.com/cqu-qxl/p/11511714.html