[fpc-devel] class operator overloads
    Ryan Joseph 
    genericptr at gmail.com
       
    Mon Jun 10 02:59:49 CEST 2019
    
    
  
Sorry to bring this up again but I had a thought today while working regarding class operator overloads in classes (i.e. operators that are members of classes).
If the operators in classes allowed another parameter for the left sided value could this idea be more viable? Unless I’m mistaken I think this would make it possible to do the memory management required.
============
type
  TMyClass = class
    public
      class operator := (left: TMyClass; right: integer): TMyClass;
  end;
class operator TMyClass.:= (left: TMyClass; right: integer): TMyClass;
begin
  if not asssigned(left) then
    ; // allocate new
  else
    ; // delete old and return new (or mutate)
end;
var
  c: TMyClass;
begin
  c := 100; // c := TMyClass.:=(c, 100);
end.
Regards,
	Ryan Joseph
    
    
More information about the fpc-devel
mailing list