Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-09

Generic TFPGList<Record Type> gives me compiler error: Operator is not overloaded

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dennis Poon
I have this:
uses fgl;
Type
   RScene=record
     ID : Word;
     Name, Category : String;
   end;
   TSceneList=specialize TFPGList<RScene>;

The error is: Operator is not overloaded: "RScene" = "RScene"

I suppose the generic thing does not know how to compare 2 records. How do I solve that?

Dennis

Sven Barth
to Dennis Poon
Dennis Poon wrote 17 lines
I have this: uses fgl; Type RScene=record ID : Word; Name, Category : String; end; TSceneList=specialize TFPGList<RScene>; The error is: Operator is not overloaded: "RScene" = "RScene" I suppose the generic thing does not know how to compare 2 records. How do I solve that?

Provide a "=" operator overload for the record:

=== code begin ===

uses fgl;
{$modeswitch advanced_records}
Type
    RScene=record
      ID : Word;
      Name, Category : String;
      class operator = (aLeft, aRight: RScene): Boolean;
    end;
    TSceneList=specialize TFPGList<RScene>;
class operator RScene.=(aLeft, aRight: RScene): Boolean;
begin
   ...
end;

=== code end ===

Regards,
Sven

Dennis Poon
to Sven Barth

Sven,

Thanks a lot. It worked.

Generics, advanced record, customized operator ... all these new features are so cool.
I am impressed that Free Pascal has become so powerful.

Dennis

uses fgl;
Show quoted text 19 lines
> > Type > RScene=record > ID : Word; > Name, Category : String; > end; > > TSceneList=specialize TFPGList<RScene>; > > > The error is: Operator is not overloaded: "RScene" = "RScene" > > > I suppose the generic thing does not know how to compare 2 records. > How do I solve that? Provide a "=" operator overload for the record:
Sven Barth
to Dennis Poon
Dennis Poon wrote 7 lines
Sven, Thanks a lot. It worked. Generics, advanced record, customized operator ... all these new features are so cool. I am impressed that Free Pascal has become so powerful.

At least generics and operator overloads aren't that new. What's new is that generics contain less bugs (at least in 2.7.1 compared to earlier versions) and that operators can be used inside records (together with normal methods).

Regards,
Sven

Dennis Poon
to Sven Barth: At least generics and operator overloads aren't that new. What's new is that generics…

Sven,
I am still using fpc 2.6.2.

May I know whether the generics bugs for 2.6.2 are catchable at compiler times or I only get to find out at run time?

Dennis

Sven Barth wrote 28 lines
On 17.09.2013 17:39, Dennis Poon wrote: > Sven, > > Thanks a lot. It worked. > > Generics, advanced record, customized operator ... all these new > features are so cool. > I am impressed that Free Pascal has become so powerful. At least generics and operator overloads aren't that new. What's new is that generics contain less bugs (at least in 2.7.1 compared to earlier versions) and that operators can be used inside records (together with normal methods). Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal ----- No virus found in this message. Checked by AVG - www.avg.com Version: 2013.0.3408 / Virus Database: 3222/6673 - Release Date: 09/17/13
Sven Barth
to Dennis Poon
Dennis Poon wrote 5 lines
Sven, I am still using fpc 2.6.2. May I know whether the generics bugs for 2.6.2 are catchable at compiler times or I only get to find out at run time?

I'm currently not aware of any runtime bugs so all should be noticable by the compiler complaining about your code :) (and these complains can be very strange compile or link errors)

Regards,
Sven