How do you initialize a class instance which has static storage within another class?

2016-01-30 Thread Enjoys Math via Digitalmars-d-learn
class A { static B b; } class B {} doing b = new B() does NOT work. Nor could I create a this() {} at module level

Re: How do you initialize a class instance which has static storage within another class?

2016-01-30 Thread anonymous via Digitalmars-d-learn
On 30.01.2016 22:52, Enjoys Math wrote: class A { static B b; } class B {} doing b = new B() does NOT work. Nor could I create a this() {} at module level It works when you make b const/immutable: class A {static immutable B b = new B;} class B {} If you want/need b to be mutable, you can

Re: How do you initialize a class instance which has static storage within another class?

2016-01-30 Thread Enjoys Math via Digitalmars-d-learn
On Saturday, 30 January 2016 at 21:52:20 UTC, Enjoys Math wrote: class A { static B b; } class B {} doing b = new B() does NOT work. Nor could I create a this() {} at module level More info: B : A so I can't do class A { this () { if (b is null) { b = new B(); } } }

Re: How do you initialize a class instance which has static storage within another class?

2016-01-30 Thread Chris Wright via Digitalmars-d-learn
On Sat, 30 Jan 2016 22:02:10 +, Enjoys Math wrote: > On Saturday, 30 January 2016 at 21:52:20 UTC, Enjoys Math wrote: >> >> class A { static B b; } class B {} >> >> doing b = new B() does NOT work. >> >> Nor could I create a this() {} at module level > > More info: > > B : A > > so I can't