Am 23.09.2013 09:10 schrieb "Xiangrong Fang" <xrf...@gmail.com>: > > Hi All, > > I wrote a TTree generic class, the code is here: > > https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas > > While using this class, I encountered the following problem: > > program project1; > {$mode objfpc}{$H+} > uses tree; > type > TIntTree = class(specialize TTree<Integer>) > end; > var > ti : TIntTree; > begin > ti := TIntTree.Create(1, nil); > ti := ti.Next; <-- error here > end. > > The error message is: > > Error: Incompatible types: got "TIntTree.TTree$LongInt" expected "TIntTree" > > If I do not inherit TTree but just specialize it, there is no error. > > How can I solve this problem so that I don' t have to use typecast everywhere?
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. Why are you subclassing in this case anyway? Regards, Sven
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal