【发布时间】:2013-10-14 20:24:22
【问题描述】:
如果我在interface 中输入我的记录定义,然后按ctrl + alt + C Delphi 会填写以下存根。
class operator P<T>.GreaterThan(a, b: P<T>): Boolean;
begin
inherited; <<-- ???
end;
您不能从记录继承,inherited 在这种情况下是什么意思?
而 Delphi 甚至不一致:
界面:
class operator Implicit(a: pointer): P<T>; inline;
class operator Implicit(a: P<T>): pointer; inline;
class operator Implicit(Cell: TCell<T>): P<T>; inline;
class operator Implicit(P: P<T>): TCell<T>; inline;
实施:
class operator P<T>.Implicit(a: pointer): P<T>;
begin <<--- nothing
end;
class operator P<T>.Implicit(a: P<T>): pointer;
begin
inherited; <<-- now you see it...
end;
class operator P<T>.Implicit(Cell: TCell<T>): P<T>;
begin <<-- now you don't
end;
class operator P<T>.Implicit(P: P<T>): TCell<T>;
begin
end;
我怀疑 Delphi 将一个运算符作为“前导”(没有继承)并在例程中使用 inherited 遵循该实现,如果它决定参数兼容的话。
inherited 在这种情况下是什么意思?
额外问题
Delphi 遵循哪些规则以及需要注意哪些陷阱?
【问题讨论】:
标签: delphi operator-overloading delphi-xe2