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? */
}
最佳答案
pBase->Base::foo()
关于c++ - 如何通过指向派生类的基类指针调用基类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1136249/