Error C2593: Operator = is ambiguous

Go To StackoverFlow.com

1

typedef map<wstring , IWString> REVERSETAG_CACHE ;
REVERSETAG_CACHE::iterator   revrsetagcacheiter;
.
.
.
wstring strCurTag;
strCurTag =  revrsetagcacheiter->second; //Error C2593

Error C2593: Operator = is ambiguous

Why does the above assignment give this error? It works in VC6. Does not compile in VC9.

2009-06-16 08:25
by bobbyalex
Please give the whole error message. It should at least state the possible call candidates. Or does it really just state "it's ambiguous" - Johannes Schaub - litb 2009-06-16 08:43
That's exactly what the error says. Error C2593: Operator '=' is ambiguous - bobbyalex 2009-06-16 08:46


2

revrsetagcacheiter->second is of type IWString . Hence it won't compile. I don't think it will compile in VC6 also.

I'll try one final time: Is your BasicString class c_str() method ? If so try converting it to wstring using std::wstring str(iter->second.c_str());

2009-06-16 08:31
by Naveen
It compiles in VC6 all right - bobbyalex 2009-06-16 08:37
Can you provide the definition of IWString. I suspect VC6 is doing multiple implicit conversions to create a wstring out of IWString as Neil suggested - Naveen 2009-06-16 08:39
typedef BasicString > IWString - bobbyalex 2009-06-16 08:43
It would also help if you can tell me how to convert from IWString to wstring - bobbyalex 2009-06-16 08:44
I suggest to do it like this: IWString iWstr = revrsetagcacheiter->second ; std::wstring strCurTag = iWstr; ( I hope this is the direct conversion - Naveen 2009-06-16 08:51
Isn't this the original problem? std::wstring strCurTag = iWstr - bobbyalex 2009-06-16 08:55
No it does it in two steps. Do try it once - Naveen 2009-06-16 08:57
So BasicString is your own class? Can you provide us with the definition - Johannes Schaub - litb 2009-06-16 09:10
But whats the point. It amounts to the same thing. By the way I tried it; didnt work. Same error - bobbyalex 2009-06-16 09:13
Then please provide the definition of BasicString class - Naveen 2009-06-16 09:19
Its a huge template class. Dont think I can paste it here - bobbyalex 2009-06-16 09:30
So here is what i recommend: paste all conversion operator (like operator wchar_t*) of BasicString and constructors of wstring, and all operator= of wstring. We should be able to fig out what is going on then - Johannes Schaub - litb 2009-06-16 09:41
I guess this is what you meant Naveen.... if you want to assign later; not while initializing: strCurTag = revrsetagcacheiter->second.c_str(); Well... what do you know? It works. No more errors! Whether it will work as expected is a whole different story. I will assume for now that it works. +1 and the right answer! Thanks Naveen - bobbyalex 2009-06-16 14:25
Ahh..good that its compiling..if your c_str() of BasicString is proper then it should work how it used to work with VC6 - Naveen 2009-06-16 14:51


3

At a guess, VC6 allows more than one user-defined conversion to be applied, while (correctly) VC9 does not. Take a look at C++ implicit conversions for discussion of the general problem.

The general solution is to supply the needed conversion yourself, rather than have the compiler try to do it.

2009-06-16 08:29
by NoName


0

Try to cast what your assigning to the correct type.

Such as:

strCurTag =  (wstring)revrsetagcacheiter->second;

Better yet, you may have meant:

IWstring strCurTag;
2009-06-16 08:31
by Sev


0

You should usually avoid implicit conversions, i.e. make all of your assignments work with exactly the same type at one side and the other, especially when it's trivial to know which types are involved. Relying, or trying to rely, on implicit conversions isn't a good idea.

So if:

strCurTag =  static_cast<wstring>(revrsetagcacheiter->second);

doesn't compile, then we should start thinking about the problem.

2009-06-16 10:01
by Daniel Daranas
Doesnt work. It says error C2243: 'type cast' : conversion from 'std_ex::IWString *' to 'const std::allocator<_Ty> &' exists, but is inaccessible - bobbyalex 2009-06-16 10:22
I give up. I think I will just change strCurTag to IWString. Can you tell me how to convert IWstring to wstring? The following are members of IWstring c_str, bstr.... et - bobbyalex 2009-06-16 10:25
I'm sorry, I'm not familiar with these types. Is there any change of using alternative types? Ultimately all string-ish types should be able to give you a sequence of their characters, right - Daniel Daranas 2009-06-16 10:41