Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
To initialize an object is to give it an initial value.
There are multiple types of initialize:
There are four initialization styles, prefer the first (called list initialization) [1].
- T a { b };
- T a = { b };
- T a = b;
- T a(b);
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 17.7. Advice, page 525: '[6] Prefer {} initialization over = and () initialization'
- Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 17.7. Advice, page 525: '[9] Initialize members and bases in their order of declaration'
- Paul Deitel, Harvey Deitel. C++11 for progrgrammers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 2.4, Error Prevention Tip 2.1. page 25: 'Although it is not always necessary to initialize every variable explicitly, doing so will help you avoid many kinds of problems.'
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.
