C++C++14C++17C++20Learn C++

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

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.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++17Language FeatureLearn C++

How To Use The SVG Image Format With Skia In C++ Builder

C++C++17Language FeatureLearn C++

How To Use Skia Images in C++ Builder?

C++C++17Code SnippetGame DevelopmentLanguage FeatureLearn C++

What Is Skia In Modern C++?

C++C++17Learn C++

How To Use Skia in C++ Builder 12?