Classes and @disable this()

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 10 09:15:00 PST 2015


On Tuesday, February 10, 2015 11:16:21 via Digitalmars-d-learn wrote:
> On Monday, 9 February 2015 at 20:15:28 UTC, Jonathan M Davis
> > Why would it we even allow it? What benefit is there? It's
> > meaningless.
> > @disable this(); is for disabling the init property on structs.
> > Classes
> > themselves have no init values - and their references have null
> > as their
> > init value.
>
> No, `@disable this()` does _not_ disable the init property on
> structs. It disables default, i.e. argument-less construction.
> Which is analogous to `new MyClass()`. It makes perfect sense to
> disable argument-less construction in classes, just like with
> structs. (They are of course different, in that struct default
> constructors don't "do" anything, but that's not relevant here.)

Well, then that's a change. It used to be that @disable this() completely
disabled the init property. So, I guess now it just disables its implicit
use, which probably screws up its use for stuff like a NonNullable (which is
why it exists in the first place), but having types without an init property
definitely would make things nasty with generic code (which is where we sat
for a while, I believe).

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list