static class instances not allowed?

Eric eric at makechip.com
Tue Jun 11 07:04:21 PDT 2013


The following code does not compile:

class Foo { int x; }
class Bar { static Foo f = new Foo(); }  // compiler error
static Foo g = new Foo(); // compiler error
void main() {}

(dmd7) desk3:~/tp/d_test2/dlib>dmd T.d
T.d(4): Error: variable T.Bar.f is mutable. Only const or 
immutable class thread local variable are allowed, not T.Foo
T.d(5): Error: variable T.g is mutable. Only const or immutable 
class thread local variable are allowed, not T.Foo

Why aren't static class instances allowed?  Is there a 
work-around,
or alternative approach to this?

Thanks,

Eric


More information about the Digitalmars-d-learn mailing list