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中需要演员阵容,我怀疑它可能在西雅图发生了变化,但我只是从这里的评论中知道这一点,并且我的记忆可能很容易出错 –