0

In vc6,The code

CString strData;
int count=3;    
strData = strData.Delete(0,count);//error

execute perfectly, But In vc9 it gives an error that error C2593: 'operator =' is ambiguous

can i use only

strData.Delete(0,count);
jiten
  • 5,128
  • 4
  • 44
  • 73

1 Answers1

0

CString::Delete returns an int. This is probably not what you're like to assign to strData. Just omit the strData = part, the Delete modifies strData anyway.

Eran
  • 21,632
  • 6
  • 56
  • 89
  • If I remember correctly, `WCHAR` was defined as `unsigned short` in VC6, and on Unicode builds, `TCHAR` is a `WCHAR`. On later versions, `WCHAR` is a `wchar_t`, in VC might not consider `CString(TCHAR)` a perfect match anymore. But it might not be the case. Anyway, VC6 failed to report that bug, and newer versions do. Is your question from academic interest only, or are you trying to restore the previous behavior (in which `strData` was corrupted by that int)? – Eran Jul 02 '12 at 07:04
  • This is not for academic interest actually i have a old vc6 project and I have to convert it into 2008 then modify. – jiten Jul 02 '12 at 07:08
  • Look at the question I have edited it,Now I am using this and it show no error.So can you tell me this procedure is right or wrong. – jiten Jul 02 '12 at 07:11
  • 1
    Good. So just use `strData.Delete(0,count);`. What you had in VC6 was a bug, and I don't see any reason to keep it. If you really want to know what happened there, debug it in VC6 and see what assignment operator (not constructor, as I mistakenly said above) was used. You can then cast the `int` returned by `Delete` to use that `operator=` in VC9, but I doubt it's worth the effort... – Eran Jul 02 '12 at 07:15