Struct initialization has no effect or error?
Andre Pany
andre at s-e-a-p.de
Wed Oct 2 19:51:33 UTC 2019
On Wednesday, 2 October 2019 at 18:35:39 UTC, mipri wrote:
> On Wednesday, 2 October 2019 at 17:37:57 UTC, Brett wrote:
>> X y = {3};
>>
>> works fine.
>>
>> So one has to do
>>
>> x[0] = y;
>
> You could initialize x all at once. Complete example:
>
> import std.stdio;
>
> struct Point {
> int x, y;
>
> string toString() {
> import std.format : format;
>
> return format("(%d, %d)", x, y);
> }
> }
>
> void main() {
> Point[2] ps = [{0,0}, {4,4}];
> foreach (p; ps) writeln(p);
> }
The brace style struct initializer will likely be deprecated.
Please see here https://github.com/dlang/DIPs/pull/169
Kind regards
Andre
More information about the Digitalmars-d-learn
mailing list