Ich kenne die Syntax in FreePascal nicht, aber in Delphi sieht das so aus:
Delphi-Quellcode:
type
TExample = record
private
FValue: Integer;
public
class operator Add(const AValue1, AValue2: TExample): TExample;
class operator Implicit(const AValue: Integer): TExample;
class operator Implicit(const AValue: TExample): Integer;
class operator Implicit(const AValue: TExample): String;
end;
{ TExample }
class operator TExample.Add(const AValue1, AValue2: TExample): TExample;
begin
Result.FValue := AValue1.FValue + AValue2.FValue;
end;
class operator TExample.Implicit(const AValue: TExample): Integer;
begin
Result := AValue.FValue;
end;
class operator TExample.Implicit(const AValue: TExample): String;
begin
Result := AValue.FValue.ToString;
end;
class operator TExample.Implicit(const AValue: Integer): TExample;
begin
Result.FValue := AValue;
end;
// Beispiel:
var
Test: TExample;
begin
Test := 40;
ShowMessage(Test + 2);
end;