Post by ReneWhy is it that one cannot derive a class from AnsiString?
Because Borland explicitally does not allow it. Look at the declaration of
AnsiString in dstring.h:
class RTL_DELPHIRETURN AnsiString
{
...
};
RTL_DELPHIRETURN is a precompiler macro in sysmac.h that expands to
__declspec(delphireturn). If you look up __declspec in the documentation,
you will see the following statement:
__declspec(delphireturn)
The delphireturn argument is for internal use only by the VCL and CLX in
C++Builder. It is used for declarations of classes that were created in
C++Builder to support Object Pascal's built-in data types and language
constructs because they do not have a native C++ type. These include
Currency, AnsiString, Variant, TDateTime, and Set. The delphireturn argument
marks C++ classes for VCL- or CLX-compatible handling in function calls as
parameters and return values. This modifier is needed when passing a
structure by value to a function between Object Pascal and C++.
One consequence of that is any type declared with __declspec(delphireturn)
cannot be derived from, in order to maintain the compatibility between and
C++. Inheritance changes the structure of the type being derived. If
AnsiString could be derived from, it would not be compatible with Object
Pascal anymore.
Gambit