Would love to override default ctor of struct
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Wed Jan 23 10:35:07 UTC 2019
On Tuesday, January 22, 2019 2:38:41 PM MST Dru via Digitalmars-d wrote:
> > If D allowed struct's to have a constructor without any
> > parameters, it would not be and could not be a default
> > constructor because of how init works. It would only be a
> > constructor that was called when used explicitly.
>
> the problem is construction of static variables right?
> we could allow to define a default ctor and then give an error in
> case it is used for a static variable.
>
> A a; //would error if A has a runtime default ctor
>
> these would still work:
> A a = A.init;
> A a = void;
It's far from just static variables. For instance, init is a core part of
how arrays are initialized. You can't even put something in an array if
default initialization is disabled for that type. The language in general
assumes that everything is default-initialized, and when it can't be, you
start running running into stray places where you can't do stuff that you
can normally do. Introducing any kind of default construction to structs
would be a massive shift, and I doubt that I could come up with all of the
stuff that would be affected off the top of my head.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list