Static Initialization of Struct as UDA

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 13 15:07:52 PDT 2017


On Tuesday, 13 June 2017 at 22:04:48 UTC, jmh530 wrote:
> The code below doesn't compile because "static variable z 
> cannot be read at compile time". However, z is a static 
> variable, so I don't see why it wouldn't be available at 
> compile-time.
>
> Bug or am I missing something?
>
> struct Bar
> {
>     int x = 2;
>     int y;
> }
>
> static Bar z = {y:1};
>
> void main()
> {
>     @z int d;
>     //@Bar(2, 1) int d; //this compiles, but requires putting x 
> in there
> }

use "static immutable" as storage class. static is not enough for 
CT.


More information about the Digitalmars-d-learn mailing list