local class instance (at module-level)
ag0aep6g
anonymous at example.com
Thu Mar 14 23:45:06 UTC 2019
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);
----
More information about the Digitalmars-d-learn
mailing list