[fpc-pascal] Re: Use generic class as parameter (was: how to write enumerator for trees)
Xiangrong Fang
xrfang at gmail.com
Sun Mar 24 13:50:13 CET 2013
Thanks Sven :)
2013/3/24 Sven Barth <pascaldragon at googlemail.com>
> On 24.03.2013 03:49, Xiangrong Fang wrote:
>
>> I think the problem is not fixed in 2.7.1:
>>
>> xrfang at laptop ~/fpc $ ./compiler/ppcx64 -n -Furtl/units/x86_64-linux
>> -Fupackages/fcl-base/units/**x86_64-linux -viwn -FE/home/xrfang -Sc
>> demo2.lpr
>> Target OS: Linux for x86-64
>> Compiling demo2.lpr
>> Compiling treap.pas
>> demo2.lpr(88,11) Error: Incompatible types: got "TTreap$2$crc94C56373"
>> expected "TRoller"
>> demo2.lpr(98) Fatal: There were 1 errors compiling module, stopping
>> Fatal: Compilation aborted
>>
>
> Aha! Now that I've seen your code I know where the problem is.
>
> Your TRoller class is declared like this:
>
> === code begin ===
>
> type
> TRoller = class(specialize TTreap<PPerson, Byte>)
> //...
> end;
>
> === code end ===
>
> So TRoller is a child class of TTreap<PPerson, Byte> and thus the result
> type of Copy is TTreap<PPerson, Byte>. This is basically not related to
> generics, but to normal class inheritance. To solve this you need to adjust
> your TTreap.Copy in such a way that it doesn't use "TTreap.Create", but
> "ClassType.Create" and you must use TRoller's Copy then this way:
>
> === code begin ===
>
> r2 := r1.Copy as TRoller;
>
> === code end ===
>
>
> Regards,
> Sven
> ______________________________**_________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130324/96f85280/attachment.html>
More information about the fpc-pascal
mailing list