Nagging question I had that I would like answered. I was told that we can’t 
have operator overloads on classes (only records) because there is a potential 
temporary class that could be created and thus some kind of automatic memory 
management would be needed. How is this any different than function operator 
overloads? If you allocated a new class in "operator +” then you would get a 
memory leak right? If that’s true then I don’t understand why we can’t have 
them in the actual class structure.

// these both do leak

operator + (left: TClass; right: T): TClass;
begin
  result := TClass.Create(right);
end;


class operator + (left: TClass; right: T): TClass;
begin
    result := TClass.Create(right);
end;

// these both don’t leak

operator + (left: TClass; right: T): TClass;
begin
  result := left;
end;


class operator + (left: TClass; right: T): TClass;
begin
    result := left;
end;

Regards,
        Ryan Joseph

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to