Access derived type in baseclass static function template

Timoses via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 2 05:07:46 PDT 2017


Hey,

wondering whether it's possible to access the derived type from a 
function template in the base class or interface.

this T does not seem to be working, I guess because it's a static 
function and this does not exists?!


interface I
{
     static void test(this T)()
     {
         writeln(T.type.stringof);
     }
}

abstract class A
{
     static void test(this T)()
     {
         writeln(T.type.stringof);
     }
}

class B : A
{
     alias type = uint;
}
class C : I {
     alias type = int;
}

void main() {
	B.test();
	C.test();
}

Throws:
Error: template app.A.test cannot deduce function from argument 
types !()(), candidates are:
         app.A.test(this T)()
Error: template app.I.test cannot deduce function from argument 
types !()(), candidates are:
         app.I.test(this T)()


Any way I could accomplish this?


More information about the Digitalmars-d-learn mailing list