如何调用抽象方法
怎么调用抽象方法?
先看看Delphi版本,是可以编译运行的,根据创建的具体实例调用实例的test方法
------解决方案--------------------
你不能在构造或析构函数内调用虚函数!
------解决方案--------------------
楼主,理解下构造函数的意义吧!
先看看Delphi版本,是可以编译运行的,根据创建的具体实例调用实例的test方法
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TA = class
public
constructor Create();
procedure test(); virtual; abstract;
end;
TB = class(TA)
public
procedure test(); override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TB }
procedure TB.test;
begin
ShowMessage('hello world');
end;
{ TA }
constructor TA.Create;
begin
Self.test;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
obj: TA;
begin
obj := TB.Create;
obj.Free;
end;
------解决方案--------------------
你不能在构造或析构函数内调用虚函数!
------解决方案--------------------
楼主,理解下构造函数的意义吧!