<div dir="ltr"><div><div><span style="font-family:courier new,monospace">Hi All,<br><br></span></div><span style="font-family:courier new,monospace">I have the following program:<br><br>  1 program test;<br>  2 {$mode objfpc}{$H+}<br>

  3 uses tree;<br>  4 type<br>  5   TIntTree = class(specialize TTree<Integer>)<br>  6   public<br>  7     function Clone: TIntTree;<br>  8   end;<br>  9 function TIntTree.Clone: TIntTree;<br> 10 begin<br> 11   Result := TIntTree(inherited Clone);<br>

 12 end;<br> 13 var<br> 14   it1, it2 : TIntTree;<br> 15 begin<br> 16   it1 := TIntTree.Create(1, nil);<br> 17   it2 := it1.Clone;<br> 18   WriteLn(it1.ClassName);<br> 19   WriteLn(it2.ClassName);<br> 20 end.</span><br><span style="font-family:courier new,monospace"><br>

</span></div><div><span style="font-family:courier new,monospace">Which output:<br><br>TIntTree<br>TIntTree.TTree$LongInt<br><br></span></div><div><span style="font-family:courier new,monospace">The source code of TTree is here: <a href="https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas">https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas</a></span><br>

<br></div><div><span style="font-family:courier new,monospace">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?<br><br></span></div><div><span style="font-family:courier new,monospace">Regards,<br>

Xiangrong</span><br></div></div>