Template member functions conflicting
Kirk McDonald
kirklin.mcdonald at gmail.com
Mon Feb 19 04:24:15 PST 2007
Aarti_pl wrote:
> 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
Except that regular member functions and member function templates are
not equivalent: Member function templates are implicitly "final," and
are not entered into the vtable.
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d-learn
mailing list