Template in interface ?

Christopher Wright dhasenan at gmail.com
Sun Mar 1 10:48:55 PST 2009


TSalm wrote:
> Le Sun, 01 Mar 2009 03:07:16 +0100, Christopher Wright 
> <dhasenan at gmail.com> a écrit:
> 
>> TSalm wrote:
>>> Does something have an idea on how to do something like this ?
>>
>> You don't. Templates cannot participate in polymorphism. I've dealt 
>> with this in the past and ended up making another class with a 
>> template parameter that corresponds to the desired function template 
>> parameter...
>>
>> Basically, you change:
>>
>> interface IFoo
>> {
>>     void method(T)(T t);
>> }
>>
>> to:
>> interface IFoo(T)
>> {
>>     void method(T t);
>> }
>>
>> This only works in some situations.
>>
> But, in fact, I need to call a "template-method" of a "template-class", 
> for which the calling code doesn't know the type of the "template-class" 
> to call this method.
> It's why I tried to use an Interface.

The remaining way:
void methodThatUsesTemplateOnAClass(Class)(Class instance)
{
	instance.method!(SomeArgument)();
}

You just can't store these arguments easily.


More information about the Digitalmars-d-learn mailing list