HomeDelphiDelphi Error – E2518 Operator ‘%s’ must take least one ‘%s’ type in parameters

Delphi Error – E2518 Operator ‘%s’ must take least one ‘%s’ type in parameters

Delphi Compiler Error

E2518 Operator ‘%s’ must take least one ‘%s’ type in parameters

Reason for the Error & Solution

Overloading the addition operator requires that one of the parameters is the same type as the return type.

program E2518;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  TFirstRec = record
  end;
  TSecondRec = record
  end;
  TThirdRec = record
    class operator Add(_a: TFirstRec; _b: TSecondRec): TThirdRec;
end;

class operator TThirdRec.Add(_a: TFirstRec; _b: TSecondRec): TThirdRec;
begin
   // code to initialize Result from the values of _a and _b
end;

begin
  Writeln('	E2518 Operator ''%s'' must take least one ''%s'' type in parameters');
end.

See Also

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...