Classes and @disable this()

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 10 01:35:27 PST 2015


On Monday, February 09, 2015 15:25:14 Steven Schveighoffer via Digitalmars-d-learn wrote:
> Well, if I do this:
>
> class C {}
>
> I can do this:
>
> new C();
>
> Mechanisms to disable this are kind of awkward. I can define this() as
> private, but that doesn't help for intra-module calls.
>
> static class C doesn't work.
>
> It really is only useful in the case where you don't want to define a
> constructor. Which probably means -- you don't want to use a class anyway ;)
>
> But for completeness, it seems like I should be able to have the option
> of disabling something the compiler does by default. Even if it's next
> to useless.

I suppose that it makes sense if you want to make it so that the class can't
be constructed (and actually, now that I look at it, that's what
std.datetime.Clock does), but if another constructor has been declared, then
it should be probably be disallowed at compile time - especially if it's
resulting in a linker error.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list