Inheriting function template from super class
Alexey
invalid at email.address
Mon Sep 27 19:29:30 UTC 2021
On Monday, 27 September 2021 at 16:10:54 UTC, Adam D Ruppe wrote:
> This is by design, overloads only consider things declared in
> the same place.
>
> see here https://dlang.org/articles/hijack.html
thanks, Adam
I'd also like to ask about similar code.
If I'm writing code like so, I'm getting error.
What I wanted to, is `this` to be the instance of C2. how can I
do this?
the second snippet is how I worked it around (explicitly defined
and used template type parameter), but is there better solution?
```D
import std.stdio;
class C1
{
void writetext()
{
this.writetext_x();
}
void writetext_x(this T)()
{
const id = __traits(identifier, T);
pragma(msg, "generating writetext for ", id);
static assert(is(T == typeof(this)));
}
}
class C2 : C1
{
}
void main()
{
auto c2 = new C2;
c2.writetext_x();
}
```
```D
import std.stdio;
class C1
{
void writetext()
{
this.writetext_x();
}
void writetext_x(T)(T new_this)
{
const id = __traits(identifier, T);
pragma(msg, "generating writetext for ", id);
}
}
class C2 : C1
{
}
void main()
{
auto c2 = new C2;
c2.writetext_x();
}
```
More information about the Digitalmars-d-learn
mailing list