Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions



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:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden
References: 
 >Xcode 2.2 /gcc 4.0.1 problem with ambigous overloaded template functions (From: Ulrich Frotscher <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.