[fpc-pascal] class inheritance and type incompatibility

Xiangrong Fang xrfang at gmail.com
Fri Sep 27 08:03:38 CEST 2013


Hi Sven,

2013/9/26 Sven Barth <pascaldragon at googlemail.com>

>
> As you can see you are constructing a TTreeInteger class inside
> TTreeInteger.Clone and nothing in the world afterwards can turn it into a
> TTreeInt.
>

​Do you mean that casting TTreeInteger into TTreeInt is not possible
because this is to cast a parent class into a child class?  If so, how this
is possible (mentioned in my earlier question about avoid typecasting):

type
  TIntTree = class(specialize TTree<Integer>)
  end;

var
  it1, it2: TIntTree;
begin
  ... ...
  it2 := TIntTree(it1.FirstChild);
end.

This is also casting TTree$Integer (parent class) to TIntTree (child class)?

Regards,
Xiangrong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130927/8c2e5639/attachment.html>


More information about the fpc-pascal mailing list