[fpc-pascal] Virtual object methods

Marco van de Voort core at pascalprogramming.org
Fri Jun 28 08:46:06 CEST 2019


Op 27/06/2019 om 23:56 schreef Ryan Joseph:
>> On Jun 27, 2019, at 5:53 PM, Ben Grasset <operator97 at gmail.com> wrote:
>>
>> If you specifically need inheritance (combined with virtual methods) you should probably just use classes, because doing it with objects will require heap allocation regardless.
>>
> Heap allocate how so? Calling the constructor seems to fix this and puts the VMT table on the stack (I think anyways). Btw I’m doing this specifically as testing for a possible “advancedobjects” mode switch and the only reason to use objects is for inheritance on the stack (otherwise records or classes).

The core problem remains that if you have


var  x : TA;

and somehow instantiate a TB in it (for virtual method/use 
polymorphism), then the sizes of TA and  TB must match.



More information about the fpc-pascal mailing list