Need I to put overload or override words after the constructor declaration in derived class?

前端 未结 4 1022
不思量自难忘°
不思量自难忘° 2021-02-09 03:03

I have a class hierarchy, this one:

type
TMatrix = class
    protected
      //...
    public
      constructor Create(Rows, Cols: Byte);
    //...
type
  TMinMa         


        
4条回答
  •  佛祖请我去吃肉
    2021-02-09 04:00

    Overload, tells the compiler that a method has the same name with different parameters.

    Override, tells the compiler that a method overrides it virtual or dynamic declared in the base class.

    Reintroduce, will hide the virtual or dynamic method declared in the base class.

    Theses definitions are from Ray Lischner's book {Delphi in a nutshell}

    type
      TFirst = class
      private
        FValue: string;
        FNumber: Integer;
      public
        constructor Create(AValue: string; ANumber: integer);
    
        property MyValue: string read FValue write FValue;
        property MyNumber: Integer read Fnumber write FNumber; 
      end;
    
      TSecond = class(TFirst)
      public
        constructor Create(AValue: string; ANumber: Integer);
      end;
    
    constructor TFirst.Create(AValue: string; ANumber: integer);
    begin
      MyValue := AValue;
      MyNumber := ANumber;
    end;
    
    { TSecond }
    
    constructor TSecond.Create(AValue: string; ANumber: Integer);
    begin
      inherited;
    end;
    

    The TSecond as it is declared will call the create of the TFirst, without the inherited, the TSecond members stay empty.

提交回复
热议问题