关键字
__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
}
inherited MyMethod(MyParam);
或缩短inherited;
MyBaseClass::MyMethod(MyParam);
在 Delphi 中,相当于“继承”。您可以在 RTL 和 VCL 源代码中看到它的使用示例。