Search⌘ K
AI Features

Designated Initializers in C++20

The C++20 standard also gives us another handy way to initialize data members. The new feature is called designated initializers, and it might be familiar to C programmers.

The basics

In basic C++20 form, you can write:

Type obj = { .designator = val, .designator { val2 }, ... };

For example:

struct Point {
...