Initializers for Instances
Let's understand the purpose of initializers in constructors.
We'll cover the following...
Member initializer lists #
An initializer list is used to initialize the members in the constructor of a class. The list is added before the body of the constructor.
Rather than creating the variables and then assigning values to them within the constructor’s body, an initializer list initializes the variables with their particular values. The list also makes the constructor’s implementation simpler and more readable.
One may wonder why this is useful. Well, consider ...