lundi 2 décembre 2019

Retrieving the underlying type of a c++11 enum [duplicate]

This question already has an answer here:

Is there a way to determine the underlying type / size of the underlying integer of an enum (in this case uint64)?

enum ErrorMask : uint64_t
{
    ET_NONE = 0,
    ET_ENGINE = (1u << 0),
    ET_OIL = = (1u << 1),
    ...
};

In this particular example I would like to do some bitwise operations and need to convert the enum value to an integer type. I can do checks on the size of the enum value and derive the required int type from that, but I would like to know whether there is a better way.

Aucun commentaire:

Enregistrer un commentaire