C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Question on template argument deduction.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue Sep 12, 2006 11:24 pm    Post subject: Question on template argument deduction. Reply with 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?
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





PostPosted: Wed Sep 13, 2006 8:50 am    Post subject: Re: Question on template argument deduction. Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.