64 bit enum in C++?

后端 未结 10 1774
陌清茗
陌清茗 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:16

    An enum in C++ can be any integral type. You can, for example, have an enum of chars. IE:

    enum MY_ENUM
    {
       CHAR_VALUE = 'c',
    };
    

    I would assume this includes __int64. Try just

    enum MY_ENUM
    {
       LARGE_VALUE = 0x1000000000000000,
    };
    

    According to my commenter, sixlettervariables, in C the base type will be an int always, while in C++ the base type is whatever is large enough to fit the largest included value. So both enums above should work.

提交回复
热议问题