我知道有些语言允许这样做。在C ++中可以吗?
答案 0 :(得分:5)
是:
#include <iostream>
class X
{
public:
void T()
{
std::cout << "1\n";
}
};
class Y: public X
{
public:
void T()
{
std::cout << "2\n";
X::T(); // Call base class.
}
};
int main()
{
Y y;
y.T();
}
答案 1 :(得分:2)
class A
{
virtual void foo() {}
};
class B : public A
{
virtual void foo()
{
A::foo();
}
};
答案 2 :(得分:1)
是的,只需指定基类的类型。
例如:
#include <iostream>
struct Base
{
void func() { std::cout << "Base::func\n"; }
};
struct Derived : public Base
{
void func() { std::cout << "Derived::func\n"; Base::func(); }
};
int main()
{
Derived d;
d.func();
}