Template member functions conflicting

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Feb 18 07:12:27 PST 2007

"Robin Allen" <r.a3 at ntlworld.com> wrote in message 
news:er9bin$1ksb$1 at digitalmars.com...
> class Bang(T)
> {
> void fn(U)( Bang!(U) ot) {}
> void fn(int q) {}
> }
> Why do the two member functions conflict here? One takes a class instance 
> and a type, the other takes an int.
> If this is intended, and it's not possible to overload a function with a 
> template function, then maybe it should be?

The page http://www.digitalmars.com/d/template-comparison.html says that 
it's unfortunately not possible.  What's worse, you can use specialized 
template functions as that page suggests, but then you surrender IFTI, so 
you will no longer be able to write "b.fn(4)" and have it automatically 
determine that you want the int version.  You'll have to write 

The reason this isn't possible (I've heard) is that function overloading and 
template specialization are two completely separate concepts, and getting 
them to work together is very hard indeed. 

More information about the Digitalmars-d-learn mailing list