[fpc-pascal] Incompatible type for generics?

Xiangrong Fang xrfang at gmail.com
Tue Sep 24 15:50:51 CEST 2013


Hi Sven,

2013/9/23 Xiangrong Fang <xrfang at gmail.com>

>  Short answer: you can't. The same would happen with normal classes.
>>
>> Long answer: You could add an additional method "Next" to your "TIntTree"
>> which returns a "TIntTree" and just do "Result := TIntTree(inherited
>> Next);" there.
>>
> I still have problem with this strange issue.   See the demo program below:

program test;
{$mode objfpc}{$H+}
uses treap;
type
  TStringMapper = class(specialize TTreap<string, string>)
  end;
var
  sm1, sm2: TStringMapper;
  n: TStringMapper.PNode;
begin
  sm1 := TStringMapper.Create;
  for n in sm1.Reversed do WriteLn(n^.Key);   <-- but NOT here
  sm2 := sm1.Reversed;                        <-- error here
end.

Why is this?  Also, I found that the keyword "specialize" is recognized in
fpc mode, but "class" is only valid in objfpc mode, is that correct?

Regards,
Xiangrong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130924/42290bba/attachment.html>


More information about the fpc-pascal mailing list