How do I cast an int to an enum in C++?
For example:
enum Test { A, B }; int a = 1;
How do I convert a to type
a
Test castEnum = static_cast(a-1); will cast a to A. If you don't want to substruct 1, you can redefine the enum:
Test castEnum = static_cast(a-1);
A
enum
enum Test { A:1, B };
In this case Test castEnum = static_cast(a); could be used to cast a to A.
Test castEnum = static_cast(a);