June 2017
Intermediate to advanced
532 pages
12h 59m
English
Variables are initialized in one step. Using the initializer syntax, there are two different situations:
// Three identical ways to initialize an int: int x1 = 1; int x2 {1}; int x3 (1); std::vector<int> v1 {1, 2, 3}; // Vector with three ints: 1, 2, 3 std::vector<int> v2 = {1, 2, 3}; // same here std::vector<int> v3 (10, 20); // Vector with 10 ints, // each have value 20
auto v {1}; // v is int auto w {1, 2}; // error: only single elements in direct // auto initialization allowed! (this is new) auto x = {1}; // x is std::initializer_list<int> auto y = {1, 2}; // y is std::initializer_list<int> ...Read now
Unlock full access