CRTP in D?

Kagamin spam at here.lot
Thu Aug 20 00:27:51 PDT 2009


bearophile Wrote:

> grauzone:
> >Why don't you just go and try?<
> 
> Mostly because C++ isn't one of the languages I know. I don't fully understand that code.

There's really not much to understand there. The difference from mixin is that Base can inherit an interface so that Derived exposes the interface just by deriving from Base.

class Base(Derived)
{
    void interface()
    {
        // ...
        (cast(Derived)this).implementation();
        // ...
    }
 
    static void static_func()
    {
        // ...
        Derived.static_sub_func();
        // ...
    }
}
 
class Derived : Base!(Derived)
{
    void implementation(){...}
    static void static_sub_func(){...}
}



More information about the Digitalmars-d-learn mailing list