defered new feature
Jarrett Billingsley
jarrett.billingsley at gmail.com
Thu Oct 23 20:03:59 PDT 2008
On Thu, Oct 23, 2008 at 9:31 PM, downs <default_357-line at yahoo.de> wrote:
> BCS wrote:
>> A number of times I have found my self wanting to have "new C(args)"
>> return a class derived from C. I know this can be done with a static
>> function or the like but syntactically, it's unappealing.
>
> Amusing fact: you can assign to "this" in the constructor.
>
> typedef bool Bogus;
> const Bogus bogus = false;
>
> class A { this() { this = new B; } this(Bogus) { } }
>
> class B : A { this() { super(bogus); /* rest of constructor */ } }
>
I once used this looong ago when I first came to D so that attempting
to do a "new Texture(`some/file`)" twice on the same file would return
the same texture object. Of course, at the time, it didn't occur to
me that (1) that was horribly hackish or (2) that a static method
would have been much better there XD
More information about the Digitalmars-d
mailing list