1 enumeration
1 enumShapeType2 {3 Circle,4 Square,5 Rectangle6 };7 8 intMain () {9 TenShapeType shape =Circle; One A Switch(Shape) - { - CaseCircle: thecout<<"shapetype.circle"<<Endl; - Break; - CaseSquare: -cout<<"Shapetype.square"<<Endl; + Break; - CaseRectangle: +cout<<"Shapetype.rectangle"<<Endl; A Break; at default: -cout<<"unknown!"<<Endl; - } - - - in return 0; -};
2. const_cast
Const inti =0; /*error C2440: ' const_cast ': cannot convert from ' const int ' to ' int ' Conversion are a valid standard Conversion, which can performed implicitly or by use of static_cast, C-style cast or Function-style cast is a valid standard conversion that can be performed implicitly, or using static_cast, C-style conversions, functional conversions*/ //Int J = const_cast<int> (i); /*from the const INT--and int, the following 4 can be, except that the Const_cast constant conversion method is not possible, just because it is a legitimate standard conversion, in a simple way can be processed also use less advanced const_cast constant conversion*/ intj = i;//Implicit conversions intH = static_cast<int> (i);//static_cast Static Conversion intK = (intI//C-style conversion intt =int(i);//function-Type conversions /*Const INT *--and int * Using CONST_CAST constant conversion*/ int* s = const_cast<int*> (&i); /*error C2440: ' static_cast ': cannot convert from ' const int * ' to ' int * ' Conversion loses qualifiers*/ int* W = static_cast<int*> (&i); //long* L = Const_cast<long *> (&i); //error C2440: ' const_cast ': cannot convert from ' const int * ' to ' long * '
Usage of const_cast:
Returns the variable that corresponds to the constant = const_cast< the type > (constant) to which the constant belongs
The principles of conversion are:
const INT *--and int *
Basic use of C + +