[fpc-pascal] why can't we define class operator for old fashion object type, but ok for 'advanced record' type?
Michael Van Canneyt
michael at freepascal.org
Wed Aug 15 11:05:38 CEST 2018
On Wed, 15 Aug 2018, Dennis wrote:
> I was trying to use a generic class TDictionary<T> with type T. This
> class has a method that compares a variable of T with another one.
>
> When I specialize a class using this TDictionary with a type:
>
> TSecurity = object
> ....
> end;
>
>
> e.g. TNewDict = class(TDictionary<String, TSecurity>);
>
> it raise a compiler complaining that my TSecurity type has no operator =
> defined.
>
> But when I try to add like this:
>
> TSecurity = object
> ....
> class operator = (constref aLeft, aRight: TSecurity ): Boolean;
> //<---compiler Error: Procedure or Function expected
>
> end;
Did you try creating an "old-fashioned" = operator ?
Something like
Operator = (l,r : TSecurity) z : boolean;
begin
// compare here
end;
Michael.
More information about the fpc-pascal
mailing list