Non-Static Data Members Initialization in C++11
Here, you’ll see how to add default values for data members with a new C++11 feature.
We'll cover the following...
We'll cover the following...
Handling default values
You can initialize data members in various constructors, delegate them to reuse code, and inherit from base classes. Yet, we can still improve at assigning default values for data members!
See below:
As you can see, the variables are assigned their default values in the place of being declared individually. There’s no need to set values inside a constructor. It’s much better than using a default constructor because it brings declaration and initialization code together. This way, it’s harder to leave data members uninitialized!
The feature is called non-static data member initialization, or ...