C++11 allows you to provide a default value for a data member when you declare it in the class declaration. For example, lines 18–22 of Fig. 5.9 could have initialized data members aCount
, bCount
, cCount
, dCount
and fCount
to 0
as follows:
unsigned int aCount = 0; // count of A grades
unsigned int bCount = 0; // count of B grades
unsigned int cCount = 0; // count of C grades
unsigned int dCount = 0; // count of D grades
unsigned int fCount = 0; // count of F grades
rather than initializing them in the class’s constructor (Fig. 5.10, lines 10–18). In later chapters, we’ll continue discussing in-class initializers and show how they enable you to perform certain data member initializations that were not possible in earlier C++ versions.
3.144.15.43