[fpc-devel] interfaces / inheritance / again

Michael Van Canneyt michael at freepascal.org
Tue Feb 3 09:18:45 CET 2026



On Tue, 3 Feb 2026, Martin Frb via fpc-devel wrote:

> On 02/02/2026 22:59, Michael Van Canneyt via fpc-devel wrote:
>>
>>
>> On Mon, 2 Feb 2026, Martin Frb via fpc-devel wrote:
>>
>>>
>>>
>>> In a class, an overridden function can actually return a subclass of 
>>> what the virtual method returned.
>>
>> I don't understand this remark. Please explain ?
>
> See below, the overriden method returns a subclass. (works with subclass 
> as result too).
>
> program Project1;
> {$Mode objfpc}{$Interfaces corba}
> type
>   IFoo = interface end;
>   IFoo2 = interface(IFoo) end;
>
>   TBar = class
>     function abc: IFoo; virtual;
>   end;
>
>   TBar2 = class(TBar)
>     function abc: IFoo2; override; // inherited interface as result type
>   end;
>
> function TBar2.abc: IFoo2;
> begin
> end;
> function TBar.abc: IFoo;
> begin
> end;

2 remarks

- Does not compile in Delphi.

- Please use 'plain text' format for your mails. I can't copy & paste this
   code and compile: it is full of unicode spaces and whatnot. I needed a hex
   dump to understand what was happening.

Michael.


More information about the fpc-devel mailing list