a quirk in function overloading

Sean Kelly sean at f4.ca
Mon Dec 18 08:55:52 PST 2006


Hasan Aljudy wrote:
> I've recently ran across a not-so-convenient behavior of overloading of 
> functions, or rather, of function templates.
> Before I go into details, I'd like to say that I know this behavior 
> complies to the specs .. so please don't reply by saying "this is the 
> intended behaviour!!!", I already know that.
> 
> So, what am I talking about?
> 
> suppose you have a function
> 
> void func( int x ) { ... }
> 
> and, say you wanted to overload it with
> 
> void func( char[] x ) { ... }
> 
> So far so good.
> but, if you try to overload it with a templated function:
> 
> void func(T)() { ... }
> 
> woops!! template "func" conflicts with "func"!!
> 
> Problem: If you want to overload a function to take a "Type" as a 
> parameter, you can't, because func(T)() is not a function, but a 
> template with a function inside it, and, the template symbol name 
> conflicts with the other "func" functions.

So make all three template functions:

void func()( int x ) { ... }
void func(Dummy1=void, Dummy2=void)( char[] x ) { ... }
void func(T)() { ... }

Since these all must be in the same module to overload one another 
anyway, it's not like we'll have situations where users will try to 
provide overloads for library functions.


Sean



More information about the Digitalmars-d mailing list