you can't do that, you can initialize it in the constructor for the class (which isnt there yet, you need to add it). Classes don't like initialize in the body, that is the issue.
Therefore, one could be able cope with default constructors:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
struct Foo {
int x[2];
};
struct Bar {
Foo y {{7, 42}};
};
int main()
{
Bar z;
std::cout << z.y.x[1] << '\n';
}
However, writing explicit constructors is still a valid idea:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
struct Foo {
int x[2];
Foo( int a, int b ) : x{a,b} {}
};
struct Bar {
Foo y;
Bar() : y(7,42) {}
};
int main()
{
Bar z;
std::cout << z.y.x[1] << '\n';
}