[fpc-pascal] commutative operators
    Honza 
    befelemepeseveze at gmail.com
       
    Thu Dec 30 08:04:03 CET 2010
    
    
  
2010/12/29 David Emerson <dle3ab at angelbase.com>:
> On Wed 29 Dec 2010, Honza wrote:
>> IIRC you don't have to.
>
> well... I do have to. I get "can't determine which overloaded function to call"
> because I have a lot of similar-looking functions and := operators
You're right, I verified it just now. I didn't remembered it correctly.
FYI, bellow is the verification example used, later modified to
compile successfully with trunk FPC. Introduction of the ':='
operators for T1 and T2 enabled the '+' operator commutativity.
program project1;
{$mode objfpc}{$H+}
type
  T1 = record
    Dummy: Boolean;
    Value: Integer;
  end;
  T2 = record
    Dummy: String;
    Value: Integer;
  end;
operator +(A: T1; B: T2): Integer;
begin
  Result := A.Value + B.Value;
end;
operator :=(X: T1): T2;
begin
  Result.Value := X.Value
end;
operator :=(X: T2): T1;
begin
  Result.Value := X.Value
end;
var
  V1: T1;
  V2: T2;
begin
  V1.Value := 2;
  V2.Value := 3;
  Writeln(V1 + V2, ' ', V2 + V1);
end.
-- 
bflm
freepascal-bits.blogspot.com
    
    
More information about the fpc-pascal
mailing list