Run-time initialised static variables

dekevin dekevin at student.ethz.ch
Tue Feb 6 23:55:25 UTC 2018


On Tuesday, 6 February 2018 at 23:50:52 UTC, dekevin wrote:
> On Tuesday, 6 February 2018 at 23:21:36 UTC, Jonathan M Davis 
> wrote:
>> [...]
>
> Thanks a lot! I will change all my initialisations to static 
> constructors now.
> The only additional problem I have, is that ℚInf has a disabled 
> default constructor.
> Is there a way to allow shared static constructors, but not the 
> default constructor?
> struct ℚInf {
>      ℚ qval;
>      immutable static ℚInf zero;
>     @disable this();
>      shared static this() {
>           zero.qval = ℚ(0);
>      }
>      this(long num, long den) {
>           qval = ℚ(num,den); //this initialisation requires
>  dynamically linked code
>       }
> }
>
> Best,
> Kevin

I should perhaps add, that I get the following DMD error message:
source/intervalarithmeticrationals.d(15): Error: variable 
intervalarithmeticrationals.ℚInf.posinf default construction is 
disabled for type immutable(ℚInf)


More information about the Digitalmars-d-learn mailing list