Extending enums in C++?

前端 未结 10 1102
挽巷
挽巷 2020-11-29 05:08

Is there a way in C++ to extend/\"inherit\" enums?

I.E:

enum Enum {A,B,C};
enum EnumEx : public Enum {D,E,F};

or at least define a

10条回答
  •  一生所求
    2020-11-29 05:21

    I've solved in this way:

    typedef enum
    {
        #include "NetProtocols.def"
    } eNetProtocols, eNP;
    

    Of course, if you add a new net protocol in the NetProtocols.def file, you have to recompile, but at least it's expandable.

提交回复
热议问题