Named Initialization of Class Members
Explore how to use designated initialization in C++20 to assign values directly to class members by name. Learn the constraints on initialization order, how default member values work, and key differences from C to write clear and correct aggregate initializations.
We'll cover the following...
We'll cover the following...
Designated initialization enables the direct initialization of members of a class type using their names. For a union, only one initializer can be provided. As for aggregate initialization, the sequence of initializers in the curly braces has to match the declaration order of the members.
Designated initialization
Line 18 and 19 use designated initializers to initialize the aggregates. The initializers such as .x or .y are often called designators.
The members of the aggregate can already have ...