On 14.03.19 20:43, Jacob Carlborg wrote:
class C {
     uint i ;
     this (uint i) {
         this.i = i ;
     }

     this (uint i) shared {
         this.i = i ;
     }

     this (uint i) immutable {
         this.i = i ;
     }
}

__gshared c0 = new C(0);
shared c1 = new shared C(1);
immutable c2 = new immutable C(2);

You only need one of the constructors depending on if you want a __gshared, shared or immutable variable.

If you make it `pure`, you can use the same constructor in all cases:

----
class C {
    uint i ;
    this (uint i) pure {
        this.i = i ;
    }
}

__gshared c0 = new C(0);
shared c1 = new shared C(1);
immutable c2 = new immutable C(2);
----

Reply via email to