2
votes

I can compile successfully the below code snippet in C++Builder 6, but I can't compile it in RAD Studio Seattle:

  unsigned long x = 50;
  String s = IntToStr(x);

[bcc32 Error] Unit1.cpp(55): E2015 Ambiguity between '_fastcall System::Sysutils::IntToStr(int) at c:\program files (x86)\embarcadero\studio\17.0\include\windows\rtl\System.SysUtils.hpp:3182' and '_fastcall System::Sysutils::IntToStr(__int64) at c:\program files (x86)\embarcadero\studio\17.0\include\windows\rtl\System.SysUtils.hpp:3183'

I've checked that IntToStr definition.

C++Builder 6:

extern PACKAGE AnsiString __fastcall IntToStr(int Value)/* overload */;
extern PACKAGE AnsiString __fastcall IntToStr(__int64 Value)/* overload */;

C++Builder Seattle:

extern DELPHI_PACKAGE System::UnicodeString __fastcall IntToStr(int Value)/* overload */;
extern DELPHI_PACKAGE System::UnicodeString __fastcall IntToStr(__int64 Value)/* overload */;
extern DELPHI_PACKAGE System::UnicodeString __fastcall UIntToStr(unsigned Value)/* overload */;
extern DELPHI_PACKAGE System::UnicodeString __fastcall UIntToStr(unsigned __int64 Value)/* overload */;

What is the difference between C++Builder 6 and C++ Builder Seattle?

3

3 Answers

3
votes

Basically in this scenario there exists an Ambiguity, means there are two overloads of IntToStr , expecting different argument types (int and int64). the ambiguity is to downgrade the provided long type to int or upgrade it to int64. here the parameter should be cast-ed to most matching type.

2
votes

Apart from what @Ali Kazmi said, for unsigned you need to use one of the last 2, since your value is unsigned:

UIntToStr()

I think then it will not require you to cast the value and it should compile.

Builder 6 implicitly casted unsigned values to one of the signed types, the new Builders (Since 2010) does not do so by default, you need to explicitly cast it to a signed type or use the unsigned alternatives

-1
votes

You can reduce the complexity of finding the correct converter functions for each variable type (as you have to do in Delphi) by just using one of the overloaded constructors of that mighty UnicodeString class itself, e.g.:

unsigned long x = 50;
String s(x);

Also, you can write String(MyVariableName) anywhere in your code to get a UnicodeString representation of MyVariableName.

In older CBuilder versions, String was a typedef for AnsiString. Nowadays, it's a typedef for UnicodeString.