My question: When a structure has c-tor, why can’t I statically initialize it ?
My compiler claims :
type `myStruct' must be initialized by constructor, not by `{...}'
Why is that ? I’m using gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
To illustrate, here is the struct that is rejected by the compiler.
struct myStruct
{
int a;
double b;
myStruct() { a= 0; b = 0.0; }
}
void main()
{
myStruct ms = {7, 7.7}; // Now this compiler does not accept.
}
The inclusion of a user-defined c-tor means it’s no longer an aggregate type. This would also be the case if there was no user-defined c-tor for the
structitself, but you have a non-static data-member of thestructthat is not a POD or aggregate type.