Initialization of C + + 11

Source: Internet
Author: User

different types of initialization in 1.4a.string S ("ZHL"), int i (3); Bracket Initializationb.string s= "ZHL", int i= 3; equals Sign InitializationC.int Arr[4] = {1,2,3,4}, struct TM today ={0}; Pod data with curly bracesd.struct s {int x; s (): X (0) {}}; constructor member initialization;The class member of the pod array cannot be initialized in 2.c++03, nor can the initial pod array when using new[], C + + 11 is finally unified with curly braces;ps:pod:http://www.cnblogs.com/viscount/p/5842895.html3. For structural data, direct initialization;
1   classC2 {3 intA;4 intb;5  Public:6CintIintj);7 };8C C {0,0};//c++11 only. Equivalent to C C (0,0);9 int* A =New int[3] {1,2,0}; /c++ One onlyTen classX { One   inta[4]; A  Public: -X (): a{1,2,3,4} {}//c++11, initializing array members -};

4. For containers, do not use Push_back ()
1 //c++11 container initializer2Vector vs<string>={" First","Second","Third"};3Map singers =4{ {"Lady Gaga","+1 (212) 555-7890"},5{"Beyonce Knowles","+1 (212) 555-0987"}6};

5. The class can also be initialized directly;

1 class C 2 {3  int a=7//c++11only4public:5 C (); 6 };
6. Expansion
class int c;}; int   Main () {    new A;        // c is uninitialized after new is finished;    A  new A ();     // c is initialized after new is finished; }c++03 This strange problem, so that you sometimes use the very uncomfortable, so enjoy using c++11 it!

Initialization of C + + 11

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.