Explicit default constructor for structs

Timon Gehr timon.gehr at gmx.ch
Wed Apr 9 11:33:18 PDT 2014


On 04/09/2014 04:59 PM, Benjamin Thaut wrote:
>
> Instead I would really love to have a explicit default constructor. E.g.
> it could look like this (alternative a new keyword "explicit" could be
> introduced, but introduction of new keywords is usually avoided if
> possible, AFAIK):
>
> struct Foo
> {
>    this(void)
>    {
>      // do stuff here
>    }
> }

Why not just:

struct Foo{
     this(){
         // do stuff here
     }
}

void main(){
     Foo foo1; // error, no init value
     auto foo2=Foo(); // ok
}


More information about the Digitalmars-d mailing list