[fpc-pascal] returning a generic object?
Xiangrong Fang
xrfang at gmail.com
Thu Sep 12 03:59:55 CEST 2013
Hi All,
I have this generic class:
type
generic TTree<T> = class
private
FItems: TList;
... ...
public
Data: T;
... ...
function FirstChild: TTree;
... ...
end;
function TTree.FirstChild: TTree;
begin
if FItems.Count = 0 then Exit(nil);
Exit(TTree(FItems[0]));
end;
when using it, I did:
type
TStringTree = specialize TTree<string>;
It generated a compilation error:
Error: Incompatible types: got "TTree" expected "TTree$AnsiString"
on the line "Exit(TTree(FItems[0]));" of function FirstChild.
And I tried to change it to:
Exit(TTree<T>(FItems[0]));
But is not accepted.
How to solve this? thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130912/4440f594/attachment.html>
More information about the fpc-pascal
mailing list