Item 33. Simulating Nested Functions

I l @ ve RuBoard

Difficulty: 5

C++ has nested classes, but not nested functions. When might nested functions be useful, and can they be simulated in C++?

  1. What is a nested class? Why can it be useful?

  2. What is a local class? Why can it be useful?

  3. C++ does not support nested functions. That is, we cannot write something like

     // Example 33-3 // int f( int i ) {   int j = i*2;   int g( int k )  // not valid C++   {     return j+k;   }   j += 4;   return g( 3 ); } 

    Demonstrate how it is possible to achieve the same effect in standard C++, and show how to generalize the solution.

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