Re: Perplexed about "call of overloaded 'xxx' is ambiguous"
Re: Perplexed about "call of overloaded 'xxx' is ambiguous"
- Subject: Re: Perplexed about "call of overloaded 'xxx' is ambiguous"
- From: Tommy Nordgren <email@hidden>
- Date: Thu, 4 Sep 2008 22:03:30 +0200
On Sep 4, 2008, at 6:07 PM, Matt Gough wrote:
I have been getting the above compiler error, but I can't see why.
I have the following two classes:
namespace MyNamespace{
class CUIString
{
public:
CUIString();
CUIString(const CUIString&);
CUIString(const std::wstring& ws_i, bool aBool = true);
CUIString(const std::string& s_i, bool aBool = true);
CUIString(CFStringRef cf_i, bool aBool = true);
CUIString(ConstStr255Param ps_i, bool aBool = true);
CUIString(const wchar_t* wchars_i);
CUIString(const char* chars_i);
~CUIString();
operator CFStringRef () const;
operator const std::wstring& () const;
operator const std::string& () const;
operator ConstStringPtr() const;
CUIString& operator = (const CUIString&);
CUIString& operator = (CFStringRef);
CUIString& operator = (const std::wstring&);
CUIString& operator = (const std::string&);
CUIString& operator = (ConstStr255Param);
CUIString& operator = (const wchar_t*);
CUIString& operator = (const char*);
};
}
class SomeClass {
public:
MyNamespace::CUIString GetSomeString() const;
void SetSomeString(const MyNamespace::CUIString& someString);
};
and some calling code like this:
// These three all work fine
MyNamespace::CUIString s1;
MyNamespace::CUIString s2(s1);
MyNamespace::CUIString s3 = s2;
// This works fine:
SomeClass someClass1;
SomeClass someClass2;
someClass2.SetSomeString(someClass1.GetSomeString());
// These don't work:
MyNamespace::CUIString s4(someClass1.GetSomeString());
MyNamespace::CUIString s5 = someClass1.GetSomeString();
/*
error: call of overloaded 'CUIString(MyNamespace::CUIString)' is
ambiguous
note: candidates are: MyNamespace::CUIString::CUIString(const char*)
<near match>
note: MyNamespace::CUIString::CUIString(const
unsigned char*, bool)
note: MyNamespace::CUIString::CUIString(const
__CFString*, bool)
note: MyNamespace::CUIString::CUIString(const
std::string&, bool)
note: MyNamespace::CUIString::CUIString(const
std::wstring&, bool)
note: MyNamespace::CUIString::CUIString(const
AppleCore::CUIString&)
*/
Interestingly if you plop this code in its own file it will probably
compile without any problem. Unfortunately this is not the case in
my real version of the code. MyNamespace::CUIString and SomeClass
are each part of other libraries/projects that are used by the
calling code. I suspect that there is some bad interaction between
the various library settings but I can see nothing obvious.
Can someone just confirm that I am not going mad. Why is it being
considered as ambiguous when CUIString has a CUIString(const
CUIString&) constructor ( and operator =(const CUIString&) )?
Thanks
Matt Gough
The class name CUIString is defined in more than one namespace.
For some reason, the constuctor gets declared as
MyNamespace::CUIString::CUIString(const AppleCore::CUIString&)
instead of as a copy constructor.
To fix, elaborate the Constructor declaration like this:
CUIString( const MyNamespace::CUIString &)
-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
email@hidden
_______________________________________________
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