Enum (C++)
https://en.cppreference.com/w/cpp/language/enum If the first enumerator does not have an initializer, the associated value is zero.
For any other enumerator whose definition does not have an initializer, the associated value is the value of the previous enumerator plus one.
For example,
The variables a
, b
, …, are now defined in the Color
Namespace
If you redefine the variable a
for example, in the global scope, you will get this sort of behavior:
Enum Compiler Optimization
Kajanan was explaining this to me, there are 2 ways that the compiler can interpret the enum
, either use:
- Jump Table (fast)
- If-else jumps (slow)
This is the compiler optimized way, which creates a jump table