Template member functions conflicting

Bruno Medeiros brunodomedeiros+spam at com.gmail
Mon Feb 19 04:04:15 PST 2007


Robin Allen wrote:
> 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?

They conflict, but there is an effective workaround, just turn the
function into a nullary template (template with zero parameters):

import stdext.stdio;

class Bang(T)
{
     void fn(U)(Bang!(U) ot) { writeln("U template:", typeid(U) ); }
     void fn() (int q) { writeln("nullary template");}
}


void main(char[][] args) {
	auto foo = new Bang!(char);

	foo.fn(new Bang!(char));
	foo.fn(42);
}

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D


More information about the Digitalmars-d-learn mailing list