【发布时间】:2017-04-18 19:46:08
【问题描述】:
我在一个文件中声明了以下类:
type
TCongruence = class(TObject)
private
a, b, n, numClass: integer;
solutions, vals: TSolutions;
hasSolutions: boolean;
function divides(a, b: integer): boolean;
function modulo(a, b: integer): integer;
public
constructor Create(a, b, n: integer); virtual;
function getSolutions: TSolutions; virtual;
function gcdExtended(p, q: integer): TSolutions;
class function getGCD(u, v: integer): integer;
property valA: integer read a;
property valB: integer read b;
property valN: integer read n;
property getClass: integer read numClass;
property hasSol: boolean read hasSolutions;
end;
type
TConguenceSystem = class(TCongruence)
private
system: array of TCongruence;
public
constructor Create(a: array of TCongruence); override;
function getSolutions: integer; override;
end;
如您所见,第二个是子类,因为我需要使用TCongruence 类中实现的所有功能。我已将构造函数声明为 virtual,以便我可以在后代上调用覆盖。
正确吗?我是否必须删除虚拟/覆盖并简单地使用这样的构造函数? (下)
constructor Create(a: array of TCongruence);
我想在这种情况下我隐藏了父亲的构造函数。我已经声明了这个构造函数:
constructor TConguenceSystem.Create(a: array of TCongruence);
var i: integer;
begin
SetLength(system, length(a)); // private var system: array of TCongruence
for i := Low(a) to High(a) do
begin
system[i] := a[i];
end;
solutions := false;
end;
【问题讨论】:
-
对我来说看起来不正确的层次结构。
getSolutions也改了签名 -
我认为这是正确的,我使用相同的 shema。
标签: delphi