class creation in module scope?
BCS
BCS at pathlink.com
Wed Mar 21 15:06:16 PDT 2007
Hendrik Renken wrote:
> Hi,
> i am having some trouble figuring out, why i cant instantiate my class
> within module-scope.
>
> Problem:
>
> ### A.d File ###
> module foo.A;
>
> import foo.B;
>
>
> public MyClass my = new MyClass();
>
[...]
>
> bud (using gdc) complains:
> foo/A.d:6: Error: non-constant expression new MyClass
>
>
> what am i doing wrong. thought this little example would be the same as
> on the Reference-Page on digitalmars.com
>
> thanks for you help,
> hendrik
new is a non-constant expression, and thay are not allowed at module
scope. Use a static constrctor
public MyClass my;
static this(){my = new MyClass();}
More information about the Digitalmars-d-learn
mailing list