template member function confusion

Francois Chabot francois.chabot.dev at gmail.com
Sun Apr 8 13:51:51 PDT 2012


Hello, I've been getting into the language recently, and ror the 
most part, it's going pretty smoothly.

I have finally run into the first major snag that's really making 
me scratch my head. Mind you, I can easily code around it, but 
I'd like to understand why it's not working:


Given (roughly) the following code:
class Binding
{
   ...
}

class Bar
{
   Binding[string] Bindings ;

   //cached function
   void foo( Foo target , const ref Matrix44 val ) { ... }
   void foo( Foo target , const ref Vec4 val ) { ... }
   //... more function...

   //convenience interface for non-critical code-paths
   void foo(T)( string target , const ref T val ) { foo( 
Bindings[target] , val ) ; }

}

DMD gives me the following:
Error: Bar.foo(T) conflicts with function Bar.foo at ...

Now, I can easily
A) Change the name of either one the functions (which yields a 
slightly less elegant interface)
B) Not use a template and put string versions of all the foos 
(which yields ugly code)
C) Make the binding-based interface a template and implement the 
functions through specialization (as they are unfortunately 
different enough to not be templatable). While maintaining the 
interface and conciseness, it feels like a hack to me.

I just can't wrap my head around why my current implementation 
cannot work. Any insight?


More information about the Digitalmars-d-learn mailing list