Class enumerations
An enumeration is a list of all the possible values in a logical collection. C++ enumerations are a great way of, well, enumerating things. For example, if our game uses variables, which can only be in a specific range of values, and if those values could logically form a collection or a set, then enumerations are probably appropriate to use. They will make your code clearer and less error-prone.
To declare a class enumeration in C++ we use two keywords, enum and class, together, followed by the name of the enumeration, followed by the values the enumeration can contain, enclosed in a pair of curly braces {...}.
As an example, examine this enumeration declaration. Note that it is conventional to declare the possible values from ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access