[fpc-pascal] class inheritance and type incompatibility

Xiangrong Fang xrfang at gmail.com
Mon Sep 30 04:07:54 CEST 2013


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?

Thanks a lot.

Xiangrong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130930/5d52078f/attachment.html>


More information about the fpc-pascal mailing list