Hi All, I have the following program:
1 program test; 2 {$mode objfpc}{$H+} 3 uses tree; 4 type 5 TIntTree = class(specialize TTree<Integer>) 6 public 7 function Clone: TIntTree; 8 end; 9 function TIntTree.Clone: TIntTree; 10 begin 11 Result := TIntTree(inherited Clone); 12 end; 13 var 14 it1, it2 : TIntTree; 15 begin 16 it1 := TIntTree.Create(1, nil); 17 it2 := it1.Clone; 18 WriteLn(it1.ClassName); 19 WriteLn(it2.ClassName); 20 end. Which output: TIntTree TIntTree.TTree$LongInt The source code of TTree is here: https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas Why the typecast on line 11 does not work? How to modify the code so that the cloned object has same type as the original one? Regards, Xiangrong
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal