Template method and overloading

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue May 29 13:57:37 PDT 2007


"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message 
news:f3i3uc$2vkn$1 at digitalmars.com...
> "gerleim" <elf_qt at _deletethisifyouarenotaspammer_yahoo.com> wrote in 
> message news:f3hvvt$2q18$1 at digitalmars.com...
>> Oh, I see, thanks. Didn't know that template parameter lists have to 
>> differ.
>> (Is that documented?)
>>
>
> It's because templated functions are really just syntactic sugar.  So:
>
> void foo(T)(int x){}
> void foo(T)(int x, float y){}
>
> Is really seen by the compiler as:
>
> template foo(T) { void foo(int x){} }
> template foo(T) { void foo(int x, float y){} }
>
> Now it looks obvious that there should be an error, because it's the 
> templates that are at top-level, not the functions.

But after posting that, I now don't know how the compiler thinks this is any 
easier to deal with:

template foo(T) { void foo(int x){} }
template foo(T, dummy = void) { void foo(int x, float y){} }

How does it find the foo(int x, float y)?  Maybe it's buried in weird 
template rules I don't entirely understand.. 




More information about the Digitalmars-d-learn mailing list