Chapter 9. Equivalent Code?

Difficulty: 5

Can subtle code differences really matter, especially in something as simple as postincrementing a function parameter? This Item explores an interesting interaction that becomes important in STL-style code.

  1. Describe what the following code does:

    // Example 9-1
    //
    f( a++ );
    

    Be as complete as you can about all possibilities.

  2. What is the difference, if any, between the following two code fragments?

    // Example 9-2(a)
    //
    f( a++ );
    
    // Example 9-2(b)
    //
    f( a );
    a++;
    
  3. In Question #2, make the simplifying assumption that f() is a function that takes its argument by value, and that a is an object of class type that has an operator++(int) with natural semantics. Now what is the difference, if any, between Example 9-2(a) ...

Get More Exceptional C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.