Delphi:方法'创建'隐藏基础的虚拟方法 - 但它在那里 [英] Delphi: Method 'Create' hides virtual method of base - but it's right there
本文介绍了Delphi:方法'创建'隐藏基础的虚拟方法 - 但它在那里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑假设的对象层次结构,从以下开始:
Consider the hypothetical object hierarchy, starting with:
TFruit = class(TObject)
public
constructor Create(Color: TColor); virtual;
end;
及其后代:
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抱怨:
方法'创建'隐藏基类型TFruit的虚拟方法
Method 'Create' hides virtual method of base type 'TFruit'
除了它不会隐藏 - 它在那里!
Except it doesn't hide it - it's right there!
- 我 覆盖祖先的虚拟方法,
- 我 重载 与另一个版本
什么是交易?
推荐答案
两种解决方案:
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;
或:
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;
这篇关于Delphi:方法'创建'隐藏基础的虚拟方法 - 但它在那里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文