Interfaces and Template Specializations

BCS ao at pathlink.com
Sat Jan 10 19:32:34 PST 2009


Reply to Björn,

>> Go to the changelog.
>> 
>> http://www.digitalmars.com/d/2.0/changelog.html
>> 
> Thanks, downloaded the code but my testcode won't compile
> 
> void tester(U)(U u) if(is(U : Plugable) && is(U : Printable))
> {
> writefln("U : Printable, Plugable");
> u.plug();
> u.print();
> }
> void tester(U)(U u)
> {
> writefln("Nothing");
> }
> When calling tester with an object that implements Plugable and
> Printable it complains that it matches more than one declaration of
> the template.
> 
> Regards,
> Björn

try 

void tester(U)(U u) if(is(U : Plugable) && is(U : Printable))
 ...
void tester(U)(U u) if(is(U : Plugable) && !is(U : Printable))
 ...

or

void tester(U)(U u)
{
   static if(is(U : Plugable)) u.plug();
   static if(is(U : Printable)) u.print();
}

or something along that line 





More information about the Digitalmars-d mailing list