Extension of C++ constructor in Borland C++Builder.
I have some code that concatenates UnicodeString
values (previously AnsiString
).
UnicodeString string="test1";
Variant v1="test";
string = string + UnicodeString(v1);
[bcc32 Error] myTest.cpp(154): E2015 Ambiguity between 'System::UnicodeString::UnicodeString(const System::UnicodeString &) at c:\program files (x86)\embarcadero\studio\17.0\include\windows\rtl\ustring.h:86' and 'System::UnicodeString::UnicodeString(const wchar_t *) at c:\program files (x86)\embarcadero\studio\17.0\include\windows\rtl\ustring.h:89'
Now, the problem is that Variant
is ambiguous and the compiler complains about this ambiguity (fair enough).
If I add direct cast to string
, it works ok.
string = string + UnicodeString(v1.As<UnicodeString>());
The problem is that my code is huge and there are thousands of such pieces. I would like to introduce a new explicit typedef or macro that does this :
Given argument v1 is Variant
, it performs instead of this:
UnicodeString(v1)
It performs this instead:
UnicodeString(v1.As<UnicodeString>())
I understand this could be achieved by extending somehow (not sure how) constructor or typedef of UnicodeString
by adding UnicodeString(Variant)
(or macro ?).
PS. UnicodeString
is a system class, so I can not modify it directly.
PS1. Same problem (even more code pieces) is with AnsiString
. Making a function does not work :( . For AnsiString
it does not work :(.
Definition of AnsiString
in system header (sysmac.h) :
typedef AnsiStringT<0> AnsiString;
Example:
AnsiString myTest::AnsiString(Variant v)
{
return "";
}
[bcc32 Error] .cpp(122): E2235 Member function must be called or its address taken
AnsiString()
, name it something likeAsAnsiString()
instead. And there is no point in making it a member of your class (unless you define it asstatic
) since it is not accessing any members of that class. And whyreturn ""
instead ofreturn v.As<AnsiString>()
? – Remy Lebeau