小编Ste*_*han的帖子

Delphi意外的覆盖行为

打开时间机器,参观古代:它是德尔福,它是2007年.

对于我们的初学者手册,我写下了编程的一些基本内容(使用Delphi).这样做我发现了一个怪癖,我不太明白.为了演示继承,我写了一个基类和它的继承人.重新引入功能,另一个功能被继承人覆盖.

unit UOverride;
interface
type
Base = class(TObject)
  strict private
    const
      CName: String = 'Base-Class';
      CMaxim: String = 'Somebody set up us the bomb.';
  public
    function GetName(): String; virtual;
    function GetMaxim(): String; virtual;

end;

Heir = class(Base)
  strict private
    const
      CName: String = 'Heir-Class';
      CMaxim: String = 'All your Base are belong to us!';
  public
    function GetName(): String; reintroduce;
    function GetMaxim(): String; override;
    function GetBaseName(): String;
    function GetBaseMaxim():String;
end;

implementation
{ Base }
function Base.GetMaxim: String;
begin
  Result := …
Run Code Online (Sandbox Code Playgroud)

theory delphi

5
推荐指数
2
解决办法
151
查看次数

标签 统计

delphi ×1

theory ×1