如何通过指向派生类的基类指针调用基类方法
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()
相关文章