Borland / Delphi __super 关键字的替代品

问题描述 投票:0回答:3

关键字

__super
是 Microsoft 特定的。它用于访问父类的虚方法。您知道 Borland C++/Delphi 编译器的替代关键字吗?

class MyBaseClass
{
    virtual void DoSomething();
};

class MyDerivedClass : public MyBaseClass
{
    virtual void DoSomething();
};

void MyBaseClass::DoSomething()
{
    // some code
}

void MyDerivedClass::DoSomething()
{
    __super::DoSomething();  // calls implementation of base class - no need to know name of base class

    // implementation specific to derived class adding new functionality
}
c++ delphi compiler-construction c++builder
3个回答
9
投票

Delphi 中的等效项是

inherited
。据我所知,C++ Builder 中没有等效项,当然
__super
是一个非标准的 MS 扩展。


8
投票
  • 德尔福:
    inherited MyMethod(MyParam);
    或缩短
    inherited;
  • C++Builder:
    MyBaseClass::MyMethod(MyParam);

3
投票

在 Delphi 中,相当于“继承”。您可以在 RTL 和 VCL 源代码中看到它的使用示例。

© www.soinside.com 2019 - 2024. All rights reserved.