Reusing enum values in separate enum types

后端 未结 2 1128
礼貌的吻别
礼貌的吻别 2021-02-07 04:58

Is there a way to reuse the same enum value in separate types? I\'d like to be able to something like the following:

enum DeviceState { UNKNOWN, ACTIVE, DISABLED         


        
2条回答
  •  一个人的身影
    2021-02-07 05:39

    You can, and should, include your enums in a namespace:

    namespace DeviceState
    {
        enum DeviceState{ UNKNOWN, ACTIVE, DISABLED, NOTPRESENT, UNPLUGGED };
    }
    namespace DeviceType
    {
        enum DeviceType{ UNKNOWN, PLAYBACK, RECORDING };
    }
    
    //...
    
    DeviceType::DeviceType x = DeviceType::UNKNOWN;
    

提交回复
热议问题