c++ - Many Enums with same members in the same class -


the title says all, give example here:

class { public:   enum    {     enumval1,     enumval2   };    enum b    {     enumval1,     enumval3,   }; }; 

what have may work?

thanks in advance.

c++11 has scoped enumerations:

class s { public:   enum class    {     enumval1,     enumval2   };    enum class b    {     enumval1,     enumval3,   }; }; 

then need refer a::enumval1 , b::enumval1. enumval2 must qualified though there no ambiguity. also, enumerators not implicitly convert , int in old style; need static_cast.

this reifying c++03 idiom:

class s { public:   struct { enum type   {     enumval1,     enumval2   } value; };    struct b { enum type    {     enumval1,     enumval3,   } value; }; }; 

then need either declare objects of type a::type , b::type, or refer .value member of struct a. (other approaches possible.)


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -