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;
}