[fpc-pascal] Virtual object methods

Ryan Joseph genericptr at gmail.com
Tue Jul 2 16:20:53 CEST 2019


Another question: what happens if you call the constructor twice? Does this create 2 VMT tables or overwrites the first? 

================================================

type
  TA = object
    constructor Create;
    procedure DoThis; virtual;
  end;

procedure TA.DoThis;
begin
  writeln('TA.DoThis');
end; 

constructor TA.Create;
begin
end;

type
  PB = ^TB;
  TB = object (TA)
    procedure DoThis; virtual;
  end;

procedure TB.DoThis;
begin
  writeln('TB.DoThis');
end; 

var
  obj: TB;
begin
  TA(obj).Create;	// creates VMT for TA
  TB(obj).Create;	// creates VMT for TB+TA?
  obj.DoThis;
end.


Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list