How to move an associative array between modules?

Adam D. Ruppe destructionator at gmail.com
Thu Jan 11 23:29:30 UTC 2018


On Thursday, 11 January 2018 at 23:20:44 UTC, WhatMeWorry wrote:
> When I simply move the array out of main() but still in app.d, 
> the compiler returns
> Error: expression ["SCRATCH":Track("scratch.wav", cast(Sound)1, 
> 0, null),...  is not a constant.
>
> Can I use "static if" or "static this()", or "mixin" or some 
> other technique?

Yeah, just declare the array outside, then initialize it inside a 
static this() constructor.

int[int] foo;
static this() {
   foo = [1:1];
}



More information about the Digitalmars-d-learn mailing list