Saturday, November 20, 2010

Anonymous Classes

The following is an example of an unnamed class:
   typedef struct {int x, int y} Pair;

For struct and class, the struct/class name is between the struct/class keywork and the opening '{'.

In C++ whenever the name of the thing is left off, the thing is said to be anonymous. Here are are some other things that can be anonymous: enums, unions, variables (e.g. return (1+2);), arrays, functions (aka functors).

Reference: C++ Templates by David Vandevoorde and Nicolai M. Josuttis. Addison-Wesley, 2003, p. 121

No comments:

Post a Comment