Basic use of C + +

Source: Internet
Author: User

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 + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.