Templated member functions in interfaces

Jason House jason.james.house at gmail.com
Wed Apr 18 17:26:30 PDT 2007


Here's a simplified version of the code I'm trying to get working. 
Honestly, I didn't expect it to work, but I was hoping...

Is there any hope for this style of usage to work?  I'm pleasantly 
surprised by it compiling at all.  In the full implementation, the 
templated calls to X occur after a few more layers of obfuscation.  If 
the below code really does compile and link correctly, I can give a more 
complex example.

Essentially, I only expect the compiler to be able to figure out how the 
interface is used, but it has to also force the classes extending from 
it to define the extra versions of foo.

File 1:
interface X{
   void foo(A)();
}

class Y: X{
   void foo(A)(){};
}

class Z: X{
   void foo{A)(){};

// etc...

File 2:
int main(char [] args){
   X y = new Y();
   X z = new Z();
   y.foo!(int)();
   z.foo!(char)();
}


More information about the Digitalmars-d-learn mailing list