Is there a way to have a 64 bit enum in C++? Whilst refactoring some code I came across bunch of #defines which would be better as an enum, but being greater than 32 bit causes the compiler to error.
For some reason I thought the following might work:
enum MY_ENUM : unsigned __int64 { LARGE_VALUE = 0x1000000000000000, };
I don’t think that’s possible with C++98. The underlying representation of enums is up to the compiler. In that case, you are better off using:
As of C++11, it is possible to use enum classes to specify the base type of the enum:
In addition enum classes introduce a new name scope. So instead of referring to
LARGE_VALUE, you would referenceMY_ENUM::LARGE_VALUE.