initializing struct containing user defined type

Ali Çehreli acehreli at yahoo.com
Fri Feb 18 14:37:25 UTC 2022


On 2/18/22 06:19, kdevel wrote:

 >     //   auto b3 = B ("A", "B"); // Error: cannot implicitly convert
 >     // expression `"A"` of type `string` to `A`

Yeah, D disallows some implicit conversions.

Adding a constructor to B will make it work:

   this(string as, string bs) {
     this.a = A(as);
     this.b = A(bs);
   }
}

Ali


More information about the Digitalmars-d-learn mailing list