Default struct constructor
Stefan Koch
uplink.coder at googlemail.com
Wed Jan 30 13:20:44 UTC 2019
On Wednesday, 30 January 2019 at 12:29:46 UTC, Victor Porton
wrote:
> Why the language specification disables default constructors
> for structs?
>
> It can be easily worked around:
>
> ---
> struct Dummy { }
>
> struct C {
> this(Dummy dummy) { }
> }
> ---
>
> But this workaround (using Dummy) is silly.
>
> Isn't it better to allow default constructor and call it for
> both of the following?
>
> C x;
> C y = C();
the reason is that a struct should have a static initialization
state.
In Practice this does not always work, but it is a nice enough
conecpt.
More information about the Digitalmars-d
mailing list