Hi There,
While playing with generics (ref. class inheritance and type
incompatibility), I have an idea to use generic class helper to overcome
the problem that generic methods cannot be virtual (because the compiler
see specialized class different than the generic one?)
I have a TTree generic class (ref:
https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas),
which currently has problem with the Clone method, I did the following:
type
generic TTreeT = class
... ...
end;
TTreeType = class of TTree;
TTreeHelper = class helper for TTreeType;
The compiler does not compile because it thinks you cannot use a class
reference (TTreeType) while defining a class helper. Why? Shouldn't class
references has same effect as a Class?
Ok, since it does not compile, I changed the last line to the following
alternatives, but NONE of them compiles:
1) TTreeHelper = class helper for TTree;
2) generic TTreeHelperT = class helper for TTreeT;
My purpose is that since the Clone method cannot be virtual (because
descendant class will not have same return type as the generic class), I
try to write a class helper for ALL specialized TTree and their descendants.
Of course I can (and will) follow Sven's advice in that email to modify my
TTree class. This email is just two other questions:
1) is it possible to define class helper for generic classes?
2) why class helper require a class and we cannot use a class reference?
Best Regards,
Xiangrong
___
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal