Template member functions conflicting

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Feb 19 05:39:54 PST 2007


"Bruno Medeiros" <brunodomedeiros+spam at com.gmail> wrote in message 
news:erc3nr$2lis$1 at digitalmars.com...
>
> 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);
> }

Huh!  Pretty sweet.  :) 




More information about the Digitalmars-d-learn mailing list