Initialization of nested struct fields
Peter Alexander via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 1 15:06:29 PST 2015
Can someone please explain this behaviour? I find it totally
bizarre.
auto f(T)(T x) {
struct S {
T y;
this(int) { }
}
return S(0);
}
void main() {
f(f(0));
}
Error: constructor f376.f!(S).f.S.this field y must be
initialized in constructor, because it is nested struct
Why must y be initialized in the constructor? It isn't const. Why
isn't it default initialized?
Is this explained anywhere in the docs? I can't see anything in
the nested struct section, or in any constructor section.
More information about the Digitalmars-d-learn
mailing list