C++ Template for mapping struct type to enum?

前端 未结 3 1820
夕颜
夕颜 2021-01-15 12:15

I have something like:

struct A { ... };
struct B { ... };
struct C { ... };

class MyEnum {
public:
    enum Value { a, b, c; }
}

template

        
3条回答
  •  天命终不由人
    2021-01-15 12:41

    Why don't you just make a static member variable of type enum and add it to your structs?

    struct A
    {
    //Stuff
    
    static MyEnum enumType; // Don't forget to assign a value in cpp
    };
    

    Than you can just do:

    MyEnum e = StructA::enumType;
    

    Or do you really want to use templates?

提交回复
热议问题