How to say to compiler that I want to inherit final template bethod of base interface into derived class
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 20 05:48:08 PDT 2014
import std.stdio;
interface IBase
{
template getStr(string fieldName)
{
final string getStr()
{
return "George";
}
}
string getStr(string fieldName);
}
class Derived: IBase
{
alias getStr = IBase.getStr; /* order matters, see below */
override string getStr(string fieldName)
{
return "Sam";
}
/* alias getStr = IBase.getStr; /* doesn't work here, I guess
that's a compiler bug */
}
void main()
{
auto obj = new Derived;
assert( obj.getStr!("aaa")() == "George" );
assert( obj.getStr("aaa") == "Sam" );
}
More information about the Digitalmars-d-learn
mailing list