Inheriting function template from super class

Alexey invalid at email.address
Mon Sep 27 16:06:47 UTC 2021


On Monday, 27 September 2021 at 14:54:41 UTC, Alexey wrote:
> hello.
> here I have some code sample.

consequently, If I want C3 to inherit form C2, I'll have to 
forward template to from C1 to C2 by hand:

```D
import std.stdio;

class C1
{
     void writetext()
     {
         this.writetext!(typeof(this))();
     }

     void writetext(alias A1)()
     {
         writeln("C1 writetext(alias A1) ", this);
     }
}

class C2 : C1
{
     override void writetext()
     {
         this.writetext!(typeof(this))();
     }

     void writetext(alias A1)()
     {
         super.writetext!(A1)();
     }
}

class C3 : C2
{
     override void writetext()
     {
         super.writetext!(typeof(this))();
     }

}

void main()
{
     auto c3 = new C3;
     c3.writetext();
}
```


More information about the Digitalmars-d-learn mailing list