This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Overload resolution compilation error
- From: "Ling-hua Tseng" <uranus at it dot muds dot net>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 20 Jul 2007 01:28:52 +0800
- Subject: Re: Overload resolution compilation error
- References: <f7o1qs$s8c$1@sea.gmane.org>
On Thu, 19 Jul 2007 12:59:09 -0300, Rodolfo Schulz de Lima wrote
> Hi, the code below doesn't compile with gcc-4.2, with the following error:
>
> test.cpp: In function ?int main()?:
> test.cpp:19: error: no matching function for call to
> ?call(<unresolved overloaded function type>)?
>
> It compiles and runs fine with Visual Studio 2005. I think the
> compiler should see that if I'm calling the non-templated 'print'
> function and there's no other non-templated 'print' overload, it
> should use 'void print()', with no ambiguity.
>
Since the sub-expression `&print' is not a call expression,
the overload resolution mechanism will not select the non-template version
first.
And the function templates can be instantiated without <>,
so the C++ compiler is confused.
This problem can be reduced to:
==========
void foo() { }
template<class T> void foo() { }
int main()
{
&foo;
}
==========
It can help you to understand what's happend.