Greetings all:
I come across an interesting question (to me anyway) and I do not
know the answer. Code/Questions follow:
#include <iostream>
#if 0
// uncommenting *should* make call ambigous because of
// odering deduction of the function signature,
// not the type of the parameter
template<typename T>
void t(T*, T const* = 0, ...) {}
#endif
// this is essentially the code presented in an earlier question
// IRC that I stumbled on; gcc-3.2.2 compiles
// doesn't denote that it's *correct* though
template<typename T>
void t(T const*, T*, T* = 0)
{ std::cout << "template func with one template parameter\n";}
// signature match previous declaration of 't' so now it's on to
// 'template' ordering rules of 'type parameter' at this point for
// the compiler
template<typename T, typename C>
void t(C const*, C*, C* = 0)
{ std::cout << "template func with two template parameters\n"; }
void example(int* p)
{
// calls t<T,C>
t<int *>(p, p);
// calls t<T>
t<>(p, p);
}
int main(int argc, char** argv)
{
example(&argc);
return 0;
}
The crux of my problem is the two seperate 'void t(...)' definitions.
That is the part I am having trouble with.
If this is legal can someone tersely explain why it works? I will do
my own homework on coverting the terse to verbose. ;)
If is not legal code then the obvious theory is I'm using a broken
compiler! - This conclusion based on the fact it compiles and excutes
instead of a compilation error for an ambigous declaration.
For what it's worth my first reaction is this should still be an
ambiguous call therefore not legal. Any input on this will be greatly
appreciated in advance. Thanks!
C Johnson
P.S. Given the noise level ealier in this group - I hope my question
is on topic and in the appropriate newsgroup! It's a joke - laugh ;)
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----