 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Tue Sep 12, 2006 11:24 pm Post subject: Question on template argument deduction. |
|
|
Hello. The both code snippets below compile fine on GCC but the second
one fails on Comeau Compiler.
// #1
template <typename T> void g(T) {}
template <typename T> void f(T, void (*)(T)) { }
int main()
{
f<int>(1, g);
}
------------------------------------------------
// #2
template <typename T> void g(T) {}
template <typename T> void f(T, void (*)(T)) {}
int main()
{
f(1, g);
}
Which compiler is right and why?
Thanks in advance.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Greg Herlihy Guest
|
Posted: Wed Sep 13, 2006 8:50 am Post subject: Re: Question on template argument deduction. |
|
|
kiryazev (AT) gmail (DOT) com wrote:
| Quote: | Hello. The both code snippets below compile fine on GCC but the second
one fails on Comeau Compiler.
// #1
template <typename T> void g(T) {}
template <typename T> void f(T, void (*)(T)) { }
int main()
{
f<int>(1, g);
}
------------------------------------------------
// #2
template <typename T> void g(T) {}
template <typename T> void f(T, void (*)(T)) {}
int main()
{
f(1, g);
}
Which compiler is right and why?
|
I would say that the Comeau compiler is correct and that the parameter
types of the function call f() cannot be deduced according to the rules
of C++.
The simple explanation is that each parameter's type in the call to f()
must first be deduced independently of the others. There is therefore
simply no way to deduce the type of function pointer g represents
because g is itself a function template which could be instantiated
with any type.
Greg
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|