August 2012
Intermediate to advanced
976 pages
30h 17m
English
When we define variables, we typically initialize them immediately rather than defining them and then assigning to them:
string foo = "Hello World!"; // define and initializestring bar; // default initialized to the empty stringbar = "Hello World!"; // assign a new value to bar
Exactly the same distinction between initialization and assignment applies to the data members of objects. If we do not explicitly initialize a member in the constructor initializer list, that member is default initialized before the constructor body starts executing. For example:
// legal but sloppier way to ...
Read now
Unlock full access