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.

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++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?