Struct initialization has no effect or error?

mipri mipri at minimaltype.com
Thu Oct 3 04:57:44 UTC 2019


On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote:
> I was trying to avoid such things since X is quite long in 
> name. Not a huge deal... and I do not like the syntax because 
> it looks like a constructor call.

It is a constructor call, though. You can define your own as well:

   #! /usr/bin/env rdmd
   import std.stdio;

   struct X {
       int a;

       this(int x) {
           a = x * 2;
       }
   }

   void main() {
       auto test = X(22);
       writeln(test.a);
   }

output: 44



More information about the Digitalmars-d-learn mailing list