C++11 before the enum type is inherited C, tepid;//c++11 to enum dynamic knife, strengthen the type check, the introduction of strong type Enum type, before the light//used Qt know, should have done so, with very cool!! I. Limitations of enum types in C//1, non-strongly typed scopes enum type1{a, B, C};enum Type2{a, D, e};//The problem comes, both enum types have a enum constant, and the scope is the same, there is a conflict//2, consent implicit type conversion if ( Type1::a = = type2::d) {;} Two different enum constants are not meaningful, but the compiler is to convert the enum constant to the int type, and then compare, will not error//3, occupy the storage space extremely symbolic uncertainty enum type3{a=1, b=0xfffffffffll};cout< <sizeof (TYPE3::A) <<endl;//may be 8, depending on the compiler, it is determined by the Chi cout<<type3::b<<endl;//output size is variable, it may be 0//problem, Storage size and symbols have undetermined factors//Two, c++11 strong type enum type//syntax: enum class type4:type{a, B, c};//Plus class, named, specify underlying type Typeenum class Type5{a, B, c};// Do not specify the underlying type//features and how to use://1, strong scope type4 t = type4::a; Strong type name must be specified type4 p = A; Error//2, non-implicit conversion if (T<TYPE4::B); The same enum type is more capable of if (T>TYPE5::B); Not the same enum type, not implicitly converted to int equivalent, no, well, the comparison if ((int) T > (int) type5::b)//coercion type conversion, can be specified by//3, can specify the underlying type enum class type6:char{a=1, b =2};enum class type7:unsigned int{a=0xffffffff};//can save space, but also can specify the symbol//third, C++11 is compatible and extends the C enum type enum type8:char{a=1, b=2};Type8 T =a;//extends and is compatible with C enum types
C++11: Strongly-typed enumeration (enum)