Why isn't field-wise constructor automatic for structs and not classes?

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 2 08:33:20 PST 2016


On Saturday, 2 January 2016 at 14:57:58 UTC, Shriramana Sharma 
wrote:
> John Colvin wrote:
>
>> Strictly speaking you aren't calling a constructor there, 
>> you're writing a struct literal.
>
> Why do you say I'm not calling a constructor?

https://dlang.org/spec/struct.html#struct-literal

> And that still doesn't answer the question of why can't we have 
> an automatic field-wise constructor for classes...

Classes aren't as simple as structs, they have hidden members, 
inherited members... Technically speaking the compiler is even 
allowed to change the ordering. They may be other reasons I'm not 
aware of / aren't thinking of right now.


More information about the Digitalmars-d-learn mailing list