实现此C#代码的正确方法是什么:
protected override void SomeMethod(inputs)
{
... do stuff ..
base.SomeMethod(inputs);
}
在C ++ / CLI中
答案 0 :(得分:8)
通过使用基类名称来定义方法名称。
void SomeMethod(inputs)
{
... do stuff ..
base::SomeMethod(inputs);
}
<强> Online Demo: 强>
#include<iostream>
class Base
{
public:
virtual void doSomething()
{
std::cout<<"In Base";
}
};
class Derived:public Base
{
public:
virtual void doSomething()
{
std::cout<<"In Derived";
Base::doSomething();
}
};
int main()
{
Base *ptr = new Derived;
ptr->doSomething();
return 0;
}