Redeclaration |
Top Previous Next |
New features since Delphi 7 > Generics > Redeclaration
Sometimes types are declared with the same name, which only differ in their template parameters. For example, there is a TList in System.pas:
TList = class(TObject)
and another TList in System.Generics.Collections:
TList<T> = class(TEnumerable<T>)
There is no problem to convert these types to C++ as they belong to different units. But sometimes such similar types are defined in the same scope, as for example IEnumerator in System.pas:
IEnumerator = interface(IInterface) ... IEnumerator<T> = interface(IEnumerator)
In C++ it is not allowed to declare both in the same scope. Therefore the re-declared type will be renamed by appending two underscores and the number of template parameters. In this case the automatic conversion results in:
class IEnumerator : public IInterface ... template<typename T>class IEnumerator__1 : public IEnumerator
A more complet example:
type
TGenRedecl = class class TGenRedecl : public System::TObject public { class function Lookup: Pointer; public: class constructor Create; static void* Lookup(); end; TGenRedecl(); };
template<typename T> TGenRedecl<T> = class(TGenRedecl) class TGenRedecl__1 : public TGenRedecl public { class function Compare: Pointer; public: class constructor Create; static void* Compare() end; { void* result; return result; } implementation TGenRedecl__1() {} };
/*#static*/ class function TGenRedecl.Lookup: Pointer; void* TGenRedecl::Lookup() begin { end; void* result = nullptr; return result; class constructor TGenRedecl.Create; } begin end; TGenRedecl::TGenRedecl() { } class function TGenRedecl<T>.Compare: Pointer; begin end;
class constructor TGenRedecl<T>.Create; begin end;
function test: boolean; bool test() var { t1 : TGenRedecl; bool result = false; t2 : TGenRedecl<integer>; TGenRedecl* t1 = nullptr; t3 : TGenRedecl<string>; TGenRedecl__1<int>* t2 = nullptr; begin TGenRedecl__1<string>* t3 = nullptr; t1 := TGenRedecl.Create; t1 = new TGenRedecl(); t2 := TGenRedecl<integer>.Create; t2 = new TGenRedecl__1<int>(); t3 := TGenRedecl<string>.Create; t3 = new TGenRedecl__1<string>(); ... ...
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |