Non-covariance and overrides

Jacob Carlborg doob at me.com
Mon Sep 2 23:56:07 PDT 2013


On 2013-09-02 17:00, Joseph Rushton Wakeling wrote:

> P.S. If I don't find a handy inheritance-based way to do this, what I'll
> probably do is something along the lines of,
>
>      class MyFakeSubclass
>      {
>          MyBaseClass base;
>
>          // ... extra data ...
>
>          // ... manually-written wrappers
>      }

You can use a template mixin or alias this.

Template mixin:

template MyBaseClassMixin ()
{
     void foo () { } // all your methods here
}

class MyFakeSubclass
{
     mixin MyBaseClassMixin;
}

http://dlang.org/template-mixin.html

Or using alias this:

class MyFakeSubclass
{
     MyBaseClass base
     alias base this;
}

Every method not available in MyFakeSubclass will be forwarded to "base".

http://dlang.org/class.html#AliasThis

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list