C++11 List Initialization

Image

C++11 introduces a new variable initialization syntax. List initialization (also called uniform initialization) enables you to use one syntax to initialize a variable of any type. Consider line 11 of Fig. 4.12

unsigned int studentCounter = 1;

In C++11, you can write this as

unsigned int studentCounter = { 1 };

or

unsigned int studentCounter{ 1 };

The braces ({ and }) represent the list initializer. For a fundamental-type variable, you place only one value in the list initializer. For an object, the list initializer can be a comma-separated list of values that are passed to the object’s constructor. For example, ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.