Whats going on with this?

claptrap clap at trap.com
Sat Oct 3 10:52:37 UTC 2020


On Saturday, 3 October 2020 at 00:15:02 UTC, Steven Schveighoffer 
wrote:
> On 10/2/20 7:28 PM, claptrap wrote:
>
>> Why would putting in the writeln cause it to fail? Is it maybe 
>> trying to create the foo at compile time?
>> 
>
> Yes, it is. Any static initialization of static variables 
> happens at compile-time.
>
> https://dlang.org/spec/declaration.html#global_static_init
>
> -Steve

Ah.. ok, any idea why this works?

Foo foo = [300,300];

Tbh I though I'd defined opAssign to take an array, and was just 
seeing if it worked, but I hadn't and it seems it's calling the 
constructor that takes an array, but I cant see in the docs why 
the above code gets converted to a constructor call.



More information about the Digitalmars-d-learn mailing list