Monday, August 7, 2017

C++11: enum class

enum classes do not get implicitly converted to an integer. enum classes are scoped. Here is an example:

enum Alpha {A, B, C};
enum class Beta {X, Y, Z};
int main()
    Alpha alpha = A;
    Beta  beta  = Beta::X;
    int   alpha_int = alpha;
    int   beta_int  = static_cast(beta); // Cast is necessary in order to compile.
    return 0;

1 comment: