Aggregate initialization is amazing, you don’t even have to have the right to nesting to make it work, and you can also provide fewer than members:
#include <iostream>
#include <string>
struct A {
struct { int a; std::string b[3]; } a;
double b, c;
};
int main() {
A a = { 10, "a", "b", "c", 3.1415 };
std::cout << a.a.a << " " << a.a.b[0] << " " << a.a.b[2]
<< " " << a.b << " " << a.c;
}
Live
source
share