views:

1058

answers:

4
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.

+3  A: 

At a guess, VC6 allows more than one user-defined conversion to be applied, while (correctly) VC9 does not. Take a look at http://stackoverflow.com/questions/867462/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.

anon
A: 

Try to cast what your assigning to the correct type.

Such as:

strCurTag =  (wstring)revrsetagcacheiter->second;

Better yet, you may have meant:

IWstring strCurTag;
Sev
+1  A: 

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());

Naveen
It compiles in VC6 all right.
Bobby Alexander
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
typedef BasicString<wchar_t, char_traits_i<wchar_t> > IWString;
Bobby Alexander
It would also help if you can tell me how to convert from IWString to wstring.
Bobby Alexander
I suggest to do it like this: IWString iWstr = revrsetagcacheiter->second ; std::wstring strCurTag = iWstr; ( I hope this is the direct conversion)
Naveen
Isn't this the original problem?std::wstring strCurTag = iWstr;
Bobby Alexander
No it does it in two steps. Do try it once.
Naveen
So BasicString is your own class? Can you provide us with the definition?
Johannes Schaub - litb
But whats the point. It amounts to the same thing.By the way I tried it; didnt work. Same error.
Bobby Alexander
Then please provide the definition of BasicString class.
Naveen
Its a huge template class. Dont think I can paste it here.
Bobby Alexander
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
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.
Bobby Alexander
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
A: 

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.

Daniel Daranas
Bobby Alexander
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 IWstringc_str, bstr.... etc
Bobby Alexander
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