作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人可以解释一下为什么当我省略构造函数的可选参数时,在以下程序中出现“不兼容类型”错误(Delphi XE3)(有关详细信息,请参阅代码底部的注释)?
program Test;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Classes;
type
BaseClass = class(TObject);
ChildClass = class(BaseClass);
GenericBaseClass<T> = class
public
constructor Create(Fixed: Integer);
end;
GenericClass<T: BaseClass> = class(GenericBaseClass<T>)
public
type
TMyProc = procedure (DataObject: T) of object;
public
constructor Create(Fixed: String; Optional: TMyProc = nil);
end;
constructor GenericClass<T>.Create(Fixed: String; Optional: TMyProc);
begin
inherited Create(12);
end;
constructor GenericBaseClass<T>.Create(Fixed: Integer);
begin
inherited Create();
end;
var
Gc: GenericClass<ChildClass>;
begin
// this call is okay
Gc := GenericClass<ChildClass>.Create('', nil);
// this call fails: E2010 Incompatible types: 'ChildClass' and 'T'
Gc := GenericClass<ChildClass>.Create('');
end.
最佳答案
将 reintroduce
或 overload
添加到 GenericClass
构造函数,因为您有多个具有相同名称但参数不同的构造函数。
关于delphi - 为什么缺少可选参数会导致 "Incompatible types"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16794525/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!