| Start |
|---|
| Iteration over an enum There is no built-in to iterate over enumeration. But there are several ways with and then and then |
| Basic Enumeration Declaration Standard enumerations allow users to declare a useful name for a set of integers. The names are collectively referred to as enumerators. An enumeration and its associated enumerators are defined as follows: An enumeration is a type, one which is distinct from all other types. In this case, the name of this type is The enumerators declared within the enumeration are constant values of the type of the enumeration. Though the enumerators are declared within the type, the scope operator The scope operator can be optionally used to access an enumerator within an enumeration. So Enumerators are assigned integer values starting from 0 and increasing by 1 for each enumerator in an enumeration. So in the above case, Enumerators can also be assigned a specific value by the user; this value must be an integral constant expression. Enumerators who's values are not explicitly provided will have their value set to the value of the previous enumerator + 1. |
| Enumeration in switch statements A common use for enumerators is for switch statements and so they commonly appear in state machines. In fact a useful feature of switch statements with enumerations is that if no default statement is included for the switch, and not all values of the enum have been utilized, the compiler will issue a warning. |
| Scoped enums C++11 introduces what are known as scoped enums. These are enumerations whose members must be qualified with To access a specific color:
Scoped enums also allow you to specify the underlying type, which is the type used to represent a member. By default it is As you may notice, |
| Enum forward declaration in C++11 Scoped enumerations: Unscoped enumerations: An in-depth multi-file example can be found here: Blind fruit merchant example (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference