如何使用C++从派生类调用父函数?例如,我有一个名为的类parent,以及一个child从父派生的类.每个班级都有一个print功能.在孩子的打印功能的定义中,我想调用父母的打印功能.我该怎么做呢?
class Base
{
public:
virtual void foo()
{}
};
class Derived: public Base
{
public:
virtual void foo()
{}
};
int main()
{
Base *pBase = NULL;
Base objBase;
Derived objDerived;
pBase = &objDerived;
pBase->foo();
/*Here Derived class foo will be called, but i want this to call
a base class foo. Is there any way for this to happen? i.e. through
casting or something? */
}
Run Code Online (Sandbox Code Playgroud)