[fpc-pascal] const records passed incorrectly

Anthony Walter sysrpl at gmail.com
Mon Nov 16 19:56:17 CET 2009


On Mon, Nov 16, 2009 at 1:39 PM, Jonas Maebe <jonas.maebe at elis.ugent.be> wrote:
> For this reason, I think the Delphi operator naming decision is actually
> better than FPC's. Limiting them to classes is another matter.
>
>
> Jonas

Jonas,

Delphi doesn't limit operator overloading to classes. You can also add
overloading to in (addition to methods and inlining) records.

  TVec3 = record
    {$IFDEF D10_UP}
    function Cross(const V: TVec3): TVec3; inline;
    function Dot(const V: TVec3): Float; inline;
    procedure Normalize; inline;
    class operator Add(const A, B: TVec3): TVec3; inline;
    class operator Subtract(const A, B: TVec3): TVec3; inline;
    class operator Multiply(const A, B: TVec3): TVec3; inline;
    class operator Multiply(const A: TVec3; B: Float): TVec3; inline;
    class operator Divide(const A, B: TVec3): TVec3; inline;
    class operator Divide(const A: TVec3; B: Float): TVec3; inline;
    {$ENDIF}
    case Integer of
    0: (X, Y, Z: Float);
    1: (R, G, B: Float);
    2: (Red, Green, Blue: Float);
    3: (Heading, Pitch, Roll: Float);
    4: (Hue, Saturation, Lightness: Float);
    5: (V: array[0..2] of Float);
  end;
  PVec3 = ^TVec3;



More information about the fpc-pascal mailing list