[fpc-pascal] Incompatible type for generics?
Sven Barth
pascaldragon at googlemail.com
Tue Sep 24 16:22:44 CEST 2013
Am 24.09.2013 15:50, schrieb Xiangrong Fang:
> Hi Sven,
>
> 2013/9/23 Xiangrong Fang <xrfang at gmail.com <mailto: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.
How is PNode declared? What is the exact error?
> 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?
"specialize" is used in all modes except mode Delphi for
specializations. "class" is available in all modes except "iso", "tp"
and "fpc", but can be enabled there using {$modeswitch class}.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130924/b96472ff/attachment.html>
More information about the fpc-pascal
mailing list