Tutorial by Examples

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: enum myEnum { enumName1, enumName2, }; An enumeration is a type, one which is...
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 ...
There is no built-in to iterate over enumeration. But there are several ways for enum with only consecutive values: enum E { Begin, E1 = Begin, E2, // .. En, End }; for (E e = E::Begin; e != E::End; ++e) { // Do job with e } C++11 with enum clas...
C++11 introduces what are known as scoped enums. These are enumerations whose members must be qualified with enumname::membername. Scoped enums are declared using the enum class syntax. For example, to store the colors in a rainbow: enum class rainbow { RED, ORANGE, YELLOW, GREE...
Scoped enumerations: ... enum class Status; // Forward declaration Status doWork(); // Use the forward declaration ... enum class Status { Invalid, Success, Fail }; Status doWork() // Full declaration required for implementation { return Status::Success; } Unscoped enumerations:...

Page 1 of 1