Struct Constructors

Dicebot via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 16 15:16:08 PDT 2014


On Monday, 16 June 2014 at 22:03:28 UTC, Mark Blume wrote:
> Why exactly isn't a constructor without any parameters is not 
> allowed?
> Why does
> "Struct()" calls "Struct.opCall()," which means "Struct.init" 
> initially,
> while
> "Struct(params)" calls "Struct.this(params)?"
>
> Does "Struct(params)" also call "Struct.opCall(params)?"
>
> I am new to D and I can't seem to understand this.

http://stackoverflow.com/questions/16648273/why-can-i-not-implement-default-constructors-for-structs-in-d/16650477#16650477

Right now I think this decision was not worth it and at least 
CTFE-only constructors should be allowed. But this is not a 
simple thing to change.

Fun fact : originally in D1 days (long time ago in a galaxy far 
away) constructors were not allowed for structs at all. Good it 
has been changed :)


More information about the Digitalmars-d-learn mailing list