[fpc-devel] interfaces / inheritance / again
Martin Frb
lazarus at mfriebe.de
Tue Feb 3 00:38:25 CET 2026
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;
begin
end.
More information about the fpc-devel
mailing list