(C++) list initialization
February 24, 2017 · View on GitHub
(C++) list initialization
List initialization is a type of initialization.
List initialization is the first of the four initialization styles [1], prefer this way of initialization for named types [2].
T a { b }; //Preferred [2] T a = { b }; T a = b; T a(b);
Prefer the = syntax for the initialization in declarations using auto [3]
auto a { b }; auto a = { b }; auto a = b; //Preferred [3] auto a(b);
References
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 6.3.5. Initialization, page 159
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 6.6. Advice, page 169: '[19] Prefer the {}-initializer syntax for declarations with a named type'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 6.6. Advice, page 169: '[20] Prefer the = syntax for the initialization in declarations using auto'