[fpc-devel] class operator overloads
    Ryan Joseph 
    genericptr at gmail.com
       
    Mon Jun 10 15:28:17 CEST 2019
    
    
  
> On Jun 10, 2019, at 9:25 AM, Sven Barth via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> 
> The operator for assigning one class instance to another exists and is internal thus it is not allowed to be overloaded. 
> 
Is that true for binary operators also? The same principle could apply to them also and perhaps solve the problem you posted below.
operator + (aLeft, aRight: TSomeClass): TSomeClass;
begin
  aLeft.DoSomething(aRight);
  Result := aLeft;
end;
var
  a, b, c: TSomeClass;
begin
  a := TSomeClass.Create;
  b := TSomeClass.Create;
  c := a + b;
  a.Free;
  b.Free;
  c.Free; (* boom! *)
end.
Regards,
	Ryan Joseph
    
    
More information about the fpc-devel
mailing list