Template member functions conflicting
Aarti_pl
aarti at interia.pl
Mon Feb 19 04:10:18 PST 2007
Bruno Medeiros napisał(a):
> 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);
> }
>
Just a thought.
Couldn't be normal functions just discarded in favor of templated
versions (without need to write 2 pairs of parenthesis of course - I
mean internally in compiler)? It would probably be much more consistent
with templated versions...
Best Regards
Marcin Kuszczak
More information about the Digitalmars-d-learn
mailing list