Skip to content

Aggregate initialization

Aggregate initialization

Aggregate initialization initializes aggregate types.

1
2
add_executable(aggregate_initialization aggregate_initialization.cpp)
target_compile_features(aggregate_initialization PRIVATE cxx_std_20)

1
2
3
4
5
struct A {
    int x;
    int y;
    int z;
};

1
A a{.x = 1, .y = 4, .z = 2};

1
A c{1, 2, 3};

1
2
3
4
5
struct B {
    int x;
    A y;
    int z;
};

1
B d{.x = 1, .y = {2, 6, 5}, .z = 3};

Share Snippets