Saturday, October 9, 2010

Defining Functions inside Functions

You cannot define a function inside another function.

A famous error is when someone tries to construct an object with no constructor arguments, but leaves the parentheses in the expression. The compiler complains that you are trying to declare a function within a function.
  Examples:

     X x(1,2); // okay
     X x(1);   // okay
     X x();    // not okay
     X x;      // okay

Reference: More Exceptional C++ by Herb Sutter. Addison-Wesley, 2002., p. 209.

No comments:

Post a Comment