struct A {
int x;
struct B {
int i;
int j;
} b;
} a = { 1, { 2, 3 } };
struct base1 { int b1, b2 = 42; };
struct base2 {
base2() {
b3 = 42;
}
int b3;
};
struct derived : base1, base2 {
int d;
};
derived d1{{1, 2}, {}, 4};
derived d2{{}, {}, 4};
struct S { int a; const char* b; int c; int d = b[a]; };
S ss = { 1, "asdf" };
struct X { int i, j, k = 42; };
X a[] = { 1, 2, 3, 4, 5, 6 };
X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
struct A {
string a;
int b = 42;
int c = -1;
};
int x[] = { 1, 3, 5 };
struct S {
int y[] = { 0 }; // error: non-static data member of incomplete type
}; — end example
struct A {
int i;
static int s;
int j;
int :17;
int k;
} a = { 1, 2, 3 };
struct A;
extern A a;
struct A {
const A& a1 { A{a,a} }; // OK
const A& a2 { A{} }; // error
};
A a{a,a}; // OK
— end example
struct S { } s;
struct A {
S s1;
int i1;
S s2;
int i2;
S s3;
int i3;
} a = {
{ }, // Required initialization
0,
s, // Required initialization
0
}; // Initialization not required for A::s3 because A::i3 is also not initialized
— end example
float y[4][3] = {
{ 1, 3, 5 },
{ 2, 4, 6 },
{ 3, 5, 7 },
};
float y[4][3] = {
1, 3, 5, 2, 4, 6, 3, 5, 7
};
union u { int a; const char* b; };
u a = { 1 };
u b = a;
u c = 1; // error
u d = { 0, "asdf" }; // error
u e = { "asdf" }; // error
u f = { .b = "asdf" };
u g = { .a = 1, .b = "asdf" }; // error
— end example