Re: Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions
Re: Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions
- Subject: Re: Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions
- From: Olivier Tristan <email@hidden>
- Date: Wed, 16 Nov 2005 11:40:56 +0100
Ulrich Frotscher wrote:
Hi,
I am experiencing problems with Xcode 2.2 (gcc-4.0.1 build 5247)
compiling code with overloaded template functions. gcc complains
about ambiguous overloaded functions in the following code snippet.
To recreate just create a new project of type "Command Line Utility/C+
+ Tool", paste the snippet into main.cpp and build. The same code
compiles fine with Xcode 2.1 (gcc 4.0.0), CodeWarrior, VC7, and
Comeau (online compiler on http://www.comeaucomputing.com). I think
the code is OK, if not I would be happy to learn more about this. Is
this a bug in gcc 4.0.1? Did anyone see similar problems? What can I
do to fix the problem?
//////////////////
// File main.cpp
#include <vector>
#include <string>
template< typename T1, typename T2 >
inline std::vector<T1> foo( const std::vector<T2>& t )
{
std::vector<T1> t1;
return t1;
}
template< typename T >
inline std::vector<T> foo(const std::vector<T>& t)
{
return t;
}
std::vector<std::string> t()
{
std::vector< std::string > t;
return foo< std::string >( t );
}
int main (int argc, char * const argv[])
{
t();
return 0;
}
IMHO gcc 4.01 is right, your code is ambigous.
The problem is, you can't partially specialize function template --
pretty much just because the language says you can't
So in your case, there is two functions which matches, so the compiler
don't know what to do.
Ways to achieve the current result are explained in the url below, but
you will need to rewrite a bit your code.
http://www.gotw.ca/publications/mill17.htm
FYI, general c++ questions are generally better answered on
comp.lang.c++ newsgroup.
Hope this helps.
--
Olivier Tristan
Ultimate Sound Bank
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden