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.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
bobbyalex
  • 2,681
  • 3
  • 30
  • 51

4 Answers4

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.

Community
  • 1
  • 1
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());

Naveen
  • 74,600
  • 47
  • 176
  • 233
  • 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 Jun 16 '09 at 08:39
  • typedef BasicString > IWString; – bobbyalex Jun 16 '09 at 08:43
  • It would also help if you can tell me how to convert from IWString to wstring. – bobbyalex Jun 16 '09 at 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 Jun 16 '09 at 08:51
  • Isn't this the original problem? std::wstring strCurTag = iWstr; – bobbyalex Jun 16 '09 at 08:55
  • No it does it in two steps. Do try it once. – Naveen Jun 16 '09 at 08:57
  • So BasicString is your own class? Can you provide us with the definition? – Johannes Schaub - litb Jun 16 '09 at 09:10
  • But whats the point. It amounts to the same thing. By the way I tried it; didnt work. Same error. – bobbyalex Jun 16 '09 at 09:13
  • Then please provide the definition of BasicString class. – Naveen Jun 16 '09 at 09:19
  • Its a huge template class. Dont think I can paste it here. – bobbyalex Jun 16 '09 at 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 Jun 16 '09 at 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 Jun 16 '09 at 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 Jun 16 '09 at 14:51
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;
Sev
  • 15,401
  • 9
  • 56
  • 75
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.

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
  • Doesnt work. It says error C2243: 'type cast' : conversion from 'std_ex::IWString *' to 'const std::allocator<_Ty> &' exists, but is inaccessible. – bobbyalex Jun 16 '09 at 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.... etc – bobbyalex Jun 16 '09 at 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 Jun 16 '09 at 10:41