【问题标题】:What does inherited mean in the context of class operators在类运算符的上下文中,继承是什么意思
【发布时间】: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


    【解决方案1】:

    在这种情况下,inherited 没有任何意义,因为记录不能被继承。编译器会忽略它并且不输出任何代码。看起来代码完成变得混乱了。

    【讨论】:

    • 好的,我认为这与同一 class operator 的多个重载版本有关。
    猜你喜欢
    • 1970-01-01
    • 2013-05-07
    • 2015-09-18
    • 2017-03-29
    • 2011-03-16
    • 2011-07-09
    • 2016-07-23
    • 1970-01-01
    相关资源
    最近更新 更多