Summary of Class Data Members

Let's review all of the knowledge from all lessons.

We'll cover the following

Summary

In this course, we covered how Modern C++ simplified the initialization of data members.

First, we took a quick glance at constructors to see their different versions and how to streamline code with inherited or delegating constructors from C++11.

Later, we progressed to another valuable feature from C++11, non-static data member initialization, NSDMI. You can now declare a member variable and initialize it with a default value. The initialization will happen before each constructor body is called in the constructor initialization list.

NSDMI improved with C++14 (aggregates) and in C++20 (bit fields are now supported).

Furthermore, in C++17, we got inline variables, which means you can declare and initialize a static member without having to do that in a corresponding CPP file.

At the end of the course, we also looked at the latest features from C++20, designated initializers. This new type of initialization can make code more readable and reduce confusion when creating aggregate types with many data members.

Here’s a “summary” example that combines the features:

Get hands-on with 1400+ tech skills courses.