July 30, 2004 can't declare and initialize a static in the same expression | ||||
|---|---|---|---|---|
| ||||
Shouldn't this be legal?
D:\code\d>type test.d
class A {}
int main()
{
static A a = new A();
return 0;
}
D:\code\d>dmd test.d
test.d(5): non-constant expression new A
| ||||
July 30, 2004 Re: can't declare and initialize a static in the same expression | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | "Sean Kelly" <sean@f4.ca> wrote in message news:cee7bb$mf$1@digitaldaemon.com... > Shouldn't this be legal? > > D:\code\d>type test.d > class A {} > > int main() > { > static A a = new A(); > return 0; > } > > D:\code\d>dmd test.d > test.d(5): non-constant expression new A No, all static initializers need to be resolvable at compile time. To do run time initialization, use a static constructor. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply