3
有人可以解釋爲什麼在下面的代碼,class1List不不要求class1的有一個參數的構造函數,但class2list 確實需要等級2,有一個參數的構造函數。泛型無參數構造函數
unit Unit11;
interface
uses
System.Generics.Collections;
type
class1 = class
public
constructor Create(const i : integer); virtual;
end;
class1List<T : class1 > = class(TObjectList<T>)
public
function AddChild(const i : integer) : T;
end;
class2 = class
public
constructor Create(const i : integer);
end;
class2List<T : class2 > = class(TObjectList<T>)
public
function AddChild(const i : integer) : T;
end;
implementation
{ class1List<T> }
function class1List<T>.AddChild(const i: integer): T;
begin
Result := T.Create(i);
inherited Add(Result);
end;
{ class2List<T> }
function class2List<T>.AddChild(const i: integer): T;
begin
Result := T.Create(i);
inherited Add(Result);
end;
{ class1 }
constructor class1.Create(const i: integer);
begin
end;
{ class2 }
constructor class2.Create(const i: integer);
begin
end;
end.
有趣。謝謝你的解釋。 – Dsm
'請注意早期版本的編譯器'你會碰巧知道在哪個版本中修復了? – Johan
@Johan在XE7中需要演員陣容,我懷疑它可能在西雅圖發生了變化,但我只是從這裏的評論中知道這一點,並且我的記憶可能很容易出錯 –