EXPLORATION 65

image

Enumerations

The final mechanism for defining types in C++ is the enum keyword, which is short for enumeration. Enumerations in C++ 11 come in two flavors. One flavor originated in C and has some strange quirks. The other flavor addresses those quirks and will probably make more sense to you. This Exploration starts with the new flavor.

Scoped Enumerations

An enumerated type is a user-defined type that defines a set of identifiers as the values of the type. Define an enumerated type with the enum class keywords, followed by the name of your new type, followed by an optional colon and integer type, followed by the enumerated literals ...

Get Exploring C++ 11, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.