Automatic method overriding in sub-classes
bitwise via Digitalmars-d
digitalmars-d at puremagic.com
Thu Oct 29 06:54:12 PDT 2015
On Thursday, 29 October 2015 at 08:27:04 UTC, Daniel N wrote:
> On Thursday, 29 October 2015 at 01:52:16 UTC, bitwise wrote:
>> [...]
>
> There's a famous idiom from the C++ world which solves this,
> google CRTP...
>
> ... or see the quick hack below.
> ('final' is optional, the interface is also optional...)
>
> interface IBase
> {
> string Name();
> }
>
> class Base(T) : IBase
> {
> final string Name()
> {
> return typeof(this).stringof;
> }
> }
>
> class One : Base!One { }
> class Two : Base!Two { }
Doesn't work with multiple levels of inheritance...
Bit
More information about the Digitalmars-d
mailing list