What Are The Member Initializers And Aggregates Features in C++14?

C++14 brought us a lot of useful things that we use today. One of the great features of C++14 was the member initializers and aggregates feature that a class with default member initializers may now be an aggregate. In this post, we explain how can use member initializers and aggregates with examples.

What are the member initializers and aggregates features in C++14?

With the new C++14, a class or struct with default member initializers may now be an aggregate in definition.

If there are fewer initializer-clauses in the list than there are members in the aggregate, then each member not explicitly initialized shall be initialized from its brace-or-equal-initializer or, if there is no brace-or-equal-initializer, from an empty initializer list“. Here is an example,

Here, X.b will be 100 automatically.

Are there simple examples about member initializers and aggregates features in C++14?

This feature can be good to be used with default values (i.e. “Unknown”), here is an example.

Here, David will have 0 score and “Unknown” university, Yilmaz will have “Unknown” university.

We can use parameters in the next parameters.

Here example above, value of test.val is initiated automatically to 67 which is third char ‘C’.

Is there a full example about member initializers and aggregates feature in C++14?

Here is a full example.

The output of this example will be as follows:

For more details, please see,
this https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3605.html ,
and this https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3653.html

What Are The Member Initializers And Aggregates Features in C++14 C++ Builder logo

C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows operating system. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.