May 2017
Intermediate to advanced
590 pages
17h 18m
English
To uniformly initialize objects regardless of their type, use the brace-initialization form {} that can be used for both direct initialization and copy initialization. When used with brace initialization, these are called direct list and copy list initialization.
T object {other}; // direct list initialization T object = {other}; // copy list initialization
Examples of uniform initialization are as follows:
std::vector<int> v { 1, 2, 3 }; std::map<int, std::string> m { {1, "one"}, { 2, "two" }};
int* arr2 = new int[3]{ 1, 2, 3 };
int arr1[3] { 1, 2, 3 };
int i { 42 }; double d { 1.2 };
class foo { int ...
Read now
Unlock full access