Consider the hypothetical object hierarchy, starting with:
TFruit = class(TObject) public constructor Create(Color: TColor); virtual; end;
and its descendant:
TApple = class(TFruit) public constructor Create(); overload; virtual; constructor Create(Color: TColor); overload; override; //deprecated. Calls other constructor - maintaining the virtual constructor chain end;
The idea here is that I've overridden the virtual constructor of the base class, with an overload that also happens to be virtual.
Delphi complains:
Method 'Create' hides virtual method of base type 'TFruit'
Except it doesn't hide it - it's right there!
What's the deal?
Two solutions:
type TFruit = class(TObject) public constructor Create(Color: TColor); virtual; end; TApple = class(TFruit) public constructor Create(); reintroduce; overload; constructor Create(Color: TColor); overload; override; end;
Or:
type TFruit = class(TObject) public constructor Create; overload; virtual; abstract; constructor Create(Color: TColor); overload; virtual; end; TApple = class(TFruit) public constructor Create(); override; constructor Create(Color: TColor); override; end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With