type
TPoint = record
X, Y: Integer;
constructor Create(AX, AY: Integer);
class operator Negative(
const P: TPoint): TPoint;
class operator Inc(
const P: TPoint): TPoint;
end;
constructor TPoint.Create(AX, AY: Integer);
begin
X := AX;
Y := AY;
end;
class operator TPoint.Negative(
const P: TPoint): TPoint;
begin
Result := TPoint.Create(-P.X, -P.Y);
end;
class operator TPoint.Inc(
const P: TPoint): TPoint;
begin
Result := TPoint.Create(P.X + 1, P.Y + 1);
end;
var
P: TPoint;
begin
//operators overload only on records
P := TPoint.Create(1, 1);
Inc(P);
//p is (2, 2)
WriteLn('x = ', P.X, ', y = ', P.Y);
P := -P;
//p is (-2, -2)
WriteLn('x = ', P.X, ', y = ', P.Y);
end.