cannot initialize static array by static this()
    Jacob Carlborg via Digitalmars-d 
    digitalmars-d at puremagic.com
       
    Wed Aug 19 23:48:17 PDT 2015
    
    
  
On 2015-08-20 08:33, aki wrote:
> Following code prints "0" using
> DMD32 D Compiler v2.068.0
> Is this a bug?
>
> import std.stdio;
> class Foo {
>      static int[10] tbl;
>      static this() {
>          foreach(ref v; tbl) {
>              v = 1;
>          }
>      }
> }
> void main() {
>      writeln(Foo.tbl[0]);
> }
Not sure what's going on, but you can do this more easily using array 
operations:
static this () {
     tbl[] = 1; // assign all elements to 1
}
-- 
/Jacob Carlborg
    
    
More information about the Digitalmars-d
mailing list