I'm trying to get a basic operator overloading example working from here:
But the compiler complains about using the operator keyword in this line of the class definition:
class operator Add(a, b: OverloadsOps): OverloadsOps;
error E2123: PROCEDURE, FUNCTION, PROPERTY, or VAR expected (E2123) (IDE cursor is on the operator keyword)
I'm using Delphi explorer 2005 and the help file does include similar examples on operator overloading.
Do I have to do something to enable operator overloading??
type
OverloadsOps = class
private
FField: Integer;
public
class operator Add(a, b: OverloadsOps): OverloadsOps;
class operator Subtract(a, b: OverloadsOps): OverloadsOps;
end;
class operator OverloadsOps.Add(a, b: OverloadsOps): OverloadsOps;
begin
Result := OverloadsOps.Create;
Result.FField := a.FField + b.FField;
end;
class operator OverloadsOps.Subtract(a, b: OverloadsOps): OverloadsOps;
begin
Result := OverloadsOps.Create;
Result.FField := a.FField - b.FField;
end;
But the compiler complains about using the operator keyword in this line of the class definition:
class operator Add(a, b: OverloadsOps): OverloadsOps;
error E2123: PROCEDURE, FUNCTION, PROPERTY, or VAR expected (E2123) (IDE cursor is on the operator keyword)
I'm using Delphi explorer 2005 and the help file does include similar examples on operator overloading.
Do I have to do something to enable operator overloading??
type
OverloadsOps = class
private
FField: Integer;
public
class operator Add(a, b: OverloadsOps): OverloadsOps;
class operator Subtract(a, b: OverloadsOps): OverloadsOps;
end;
class operator OverloadsOps.Add(a, b: OverloadsOps): OverloadsOps;
begin
Result := OverloadsOps.Create;
Result.FField := a.FField + b.FField;
end;
class operator OverloadsOps.Subtract(a, b: OverloadsOps): OverloadsOps;
begin
Result := OverloadsOps.Create;
Result.FField := a.FField - b.FField;
end;