Initialization of the C++11

Source: Internet
Author: User

C++11 type initial more convenient such as

??

Vector<int> VEC = {A-i};

Vector<int> vec{1,2,3};

Map<string, int> m = {{"Help", 3}, {"Good", 4}};

??

Other common examples include how a class that you define accepts list initialization

struct class supports simpler initialization in C++11 without the use of handwritten initialization functions

Class Node

{

Public

int x;

Double y;

String Z;

};

??

Class Vec

{

Public

VEC (const initializer_list<double>& IL)

:d ATA (IL)

{

??

}

Vector<double> data;

};

??

??

TEST (Simple, func)

{

Node node{1, 3.5, "Meixi"};

Pval3 (node.x, Node.y, node.z);

??

Vec vec{1.2, 3.4, 5.6};

Pvec (Vec.data);

}

??

I0512 11:41:11.497020 2240 test_simple.cc:51] node.x--[1] node.y--[3.5] node.z--[Meixi]

I0512 11:41:11.497115 2240 test_simple.cc:54] Vec.data---3

I0512 11:41:11.497122 2240 test_simple.cc:54] 0 1.2

I0512 11:41:11.497128 2240 test_simple.cc:54] 1 3.4

I0512 11:41:11.497134 2240 test_simple.cc:54] 2 5.6

? ?

Initialization of the 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.