[fpc-pascal] Re: Use generic class as parameter (was: how to write enumerator for trees)

Xiangrong Fang xrfang at gmail.com
Fri Mar 22 08:13:47 CET 2013


2013/3/22 Sven Barth <pascaldragon at googlemail.com>


> > The problem is gone, because PNode is not a generic class, but only a
> record.   However, the following errors are generated:
>
> 2.6.x does not support nested types in generics. Generic fixes and
> improvements are only found in 2.7.1 as most of them were to invasive to be
> merged back.
>
OK, then why this error happened:

demo2.lpr(76,13) Error: Incompatible types: got
"TRoller.TTreap$PPerson$Byte" expected "TRoller"

The problematic lines are:

=== demo2.lpr ===

var
  n: TRoller.PNode;
  r1, r2: TRoller;
begin
  r1 := TRoller.Create;
  with r1 do begin
    ... ...
 *   r2 := r1.Copy(@OrderByAge);*
    ... ...
  end;
end.

=== treap.pas ===

function TTreap.Copy(Comp: TComparator): TTreap;
var
  n: PNode;
begin
  if Comp = nil then Comp := FComparator;
  Result := TTreap.Create;
  Result.Comparator := Comp;
  for n in Self do Result.Insert(n^.Key, n^.Value);
end;

I don't see there are "nested types" and why there is a type named:
TRoller.TTreap$PPerson$Byte?
Shouldn't be either
TRoller or TTreap$PPerson$Byte but not both?

Thanks,
Xiangrong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130322/210f33af/attachment.html>


More information about the fpc-pascal mailing list