Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(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

 

  1. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 6.3.5. Initialization, page 159
  2. 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'
  3. 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'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict