Der folgende Code demonstriert die Übersetzung eines generischen Delphi Types nach C++:


type
   TPair = class   // declares TPair type with two type parameters
   private
     FKey: TKey;
     FValue: TValue;
   public
     function GetKey: TKey;
     procedure SetKey(key: TKey);
     function GetValue: TValue;
     procedure SetValue(Value: TValue);
     property key: TKey Read GetKey Write SetKey;
     property Value: TValue Read GetValue Write SetValue;
   end;

 type
   TSIPair = TPair; // declares instantiated type
   TSSPair = TPair;  // declares with other data types
   TISPair = TPair;
   TIIPair = TPair;
   TSXPair = TPair;

implementation

function TPair.GetValue: TValue;
 begin
   Result := FValue;
 end;

->

// declares TPair type with two type parameters
template
class TPair : public System::TObject
{
  typedef System::TObject inherited;
private:
  TKey FKey;
  TValue FValue;
public:
  TKey GetKey() const;
  void SetKey(TKey key);
  TValue GetValue() const;
  void SetValue(TValue Value);
  /*property key : TKey read GetKey write SetKey;*/
  TKey ReadPropertykey() const { return GetKey();}
  void WritePropertykey(TKey key){SetKey(key);}
  /*property Value : TValue read GetValue write SetValue;*/
  TValue ReadPropertyValue() const { return GetValue();}
  void WritePropertyValue(TValue Value){SetValue(Value);}
public:
  TPair() {}
};
typedef TPair* TSIPair; // declares instantiated type
typedef TPair* TSSPair;  // declares with other data types
typedef TPair* TISPair;
typedef TPair* TIIPair;
typedef TPair* TSXPair;


template
TValue TPair::GetValue() const
{
  TValue result;
  result = FValue;
  return result;
}


   english english

 
Letzte Neuigkeiten
15.11.19
DelphiXE2Cpp11 Klassenreferenzen [mehr...]

16.10.19
Delphi2C# beta Angebot [mehr...]