Now you have seen structures, typedefs, and unions. The next category of user-defined data type is the enumeration. An enumeration is a user-defined type that defines named constants. Enumerations are declared using the enum keyword. An enumeration is really a set of named integer constants that specify all the values that variables of this type may have. Note that these are named integer constants. That means that we give names to integer values.

The enumerated type is declared using the following form.

enum typename {enumeration list};

enum is a C++ keyword. The compiler sees this word and knows that the definition for an enumeration is coming up. The word typename can be any valid C++ name identifier. The enumerated list is a comma-delimited list of the items in the enumeration, enclosed in brackets, and terminated by a semicolon. The following is a generic example.

enum test{value1,value2,value3};

C++ Programming Fundamentals
C++ Programming Fundamentals (Cyberrookies)
ISBN: 1584502371
EAN: 2147483647
Year: 2005
Pages: 197
Authors: Chuck Easttom

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