64 bit enum in C++?

后端 未结 10 1773
陌清茗
陌清茗 2020-12-09 16:35

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 ca

10条回答
  •  再見小時候
    2020-12-09 17:17

    If the compiler doesn't support 64 bit enums by compilation flags or any other means I think there is no solution to this one.

    You could create something like in your sample something like:

    namespace MyNamespace {
    const uint64 LARGE_VALUE = 0x1000000000000000;
    };
    

    and using it just like an enum using

    MyNamespace::LARGE_VALUE 
    

    or

    using MyNamespace;
    ....
    val = LARGE_VALUE;
    

提交回复
热议问题