how to initialize nested struct elegantly?
Steven Schveighoffer
schveiguy at gmail.com
Wed Dec 12 18:50:00 UTC 2018
On 12/12/18 4:49 AM, elvisxzhou wrote:
> dlang version has two unnecessary symbols aa and bb, which is ugly
> compare to c99 one.
>
Well, this works:
BB bb = {
f : 0.2f,
a : [
{i:1010, f:0.1f}, // note the nested field name syntax
{i:1020, f:0.2f}
]
};
writeln(bb);
But you can't use that syntax for expressions, only for initialization.
So, no you can't get rid of the bb if you want to use that syntax.
Or you can just create a factory function to do what you want.
-Steve
More information about the Digitalmars-d-learn
mailing list