Struct default constructor - need some kind of solution for C++ interop

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 7 17:40:49 PDT 2016


On 9/6/2016 6:44 AM, Ethan Watson wrote:
> Suggestions?

Provide a "default" constructor that has a dummy (i.e. unused) parameter.

     struct _Unused { }
     alias Unused = immutable(_Unused);
     Unused unused;

     ...

     struct S {
         this(Unused) { ... }
         ...
     }

     ...

     S s = S(unused);

Auto-generated such a constructor when S is used as a field.


More information about the Digitalmars-d mailing list