[fpc-pascal] class inheritance and type incompatibility

Sven Barth pascaldragon at googlemail.com
Mon Sep 30 06:50:03 CEST 2013


Am 30.09.2013 04:10 schrieb "Xiangrong Fang" <xrfang at gmail.com>:
>
> 2013/9/30 Sven Barth <pascaldragon at googlemail.com>
>>
>>
>>> However, this does not work, because it seems that I cannot make any
>>> generic method virtual!  In TIntTree, I have to write:
>>>
>>> function TIntTree.DoClone: TIntTree;
>>>
>>> As it is not possible to write TTree outside of the generic definition.
>>
>>
>> This should do it:
>
>
> Right, this worked. My last question for this issue: is the TSelfType a
2.6.2 workaround, or it is required even in 2.7.1? I mean, how about this:
>
> === code ===
> type
>   generic TTree = class
>   protected
>     procedure DoClone(aNode: TTree); virtual;  //<<-- instead of TSelfType
>   end;
>   TIntTree = class(specialize TTree<Integer)
>   protected
>     procedure DoClone(aNode: TTree); override; //<<-- instead of TSelfType
>   end;
> === end code ===
>
> In another word, use "TTree" to represent any of its specialization and
their descendants. Is it possible in 2.7.1 or later?

You don't require "TSelfType" in 2.7.1, but the correct one is not "TTree",
but "specialize TTree<Integer>". If "TTree" should work then that's a bug...

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130930/5777cd28/attachment.html>


More information about the fpc-pascal mailing list