Example error for initializer?

Tom S h3r3tic at remove.mat.uni.torun.pl
Wed Jun 21 02:23:34 PDT 2006


Paolo Invernizzi wrote:
> Hi all,
> 
> In http://www.digitalmars.com/d/arrays.html under Pointer Arithmetic 
> there's:
> 
> int[] def = [ 1, 2, 3 ];    // dynamic array of 3 ints
> 
> but does not compile (dmd .0161):
> 
>   variable xdelta.main.def is not a static and cannot have static 
> initializer

Currently only static arrays can have static initializers, so if you 
declare the 'def' inside some function, in your case 'main', it must be 
declared like this:

static int[] def = [1, 2, 3];

Declarations at global scope are static anyway, so the error does not 
occur in that case - and that's the case in the example.


-- 
Tomasz Stachowiak  /+ a.k.a. h3r3tic +/



More information about the Digitalmars-d-learn mailing list