• Delphi里可将纯虚类实例化,还可调用非虚函数


    这是与Java/C++的巨大不同。目前还没仔细想这个特征与TClass之间的联系,先记住结论再说。以后再回来修改这个帖子。

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type
    TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    TXXX = class(TObject)
    private
    FList: TList;
    protected
    function PeekItem: Pointer; virtual; abstract;
    property List: TList read FList;
    public
    constructor Create;
    destructor Destroy; override;
    procedure Show;
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    VAR
    x: TXXX;
    begin
    x:=TXXX.Create; // 实例化一点问题没有
    x.PeekItem; // 调用纯虚方法出错 // 调用Show方法正确执行
    end;

    { TXXX }

    constructor TXXX.Create;
    begin
    inherited;
    end;

    destructor TXXX.Destroy;
    begin
    inherited;
    end;

    procedure TXXX.Show;
    begin
    ShowMessage('dddd');
    end;

    end.

  • 相关阅读:
    Codeforces Round #744 (Div. 3) (CF1579) 题解
    Codeforces Round #748 (Div. 3) (CF1593)题解
    NOIP2018初赛游记
    模板:高精度
    博客园,初见安~~
    20200211学习
    nyoj 1103 区域赛系列一多边形划分
    南阳oj 845 无主之地1
    hdu 2080 夹角有多大II
    hdu 分拆素数和
  • 原文地址:https://www.cnblogs.com/findumars/p/3654860.html
Copyright © 2020-2023  润新知