How to say to compiler that I want to inherit final template bethod of base interface into derived class

Uranuz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 20 08:48:18 PDT 2014


On Sunday, 20 July 2014 at 12:48:09 UTC, anonymous wrote:
> 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" );
> 	
> }

Sorry, but this example doesn't work too.


More information about the Digitalmars-d-learn mailing list