Item 9. Equivalent Code?

I l @ ve RuBoard

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) and Example 9-2(b)?

I l @ ve RuBoard


More Exceptional C++
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions
ISBN: 020170434X
EAN: 2147483647
Year: 2001
Pages: 118
Authors: Herb Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net