How to call Base class method through base class pointer pointing to derived class

后端 未结 3 1418
陌清茗
陌清茗 2020-12-18 20:22
class Base
{
  public:
    virtual void foo()
    {}
};

class Derived: public Base
{
  public:
    virtual void foo()
    {}
};

int main()
{
    Base *pBase = NULL         


        
相关标签:
3条回答
  • 2020-12-18 20:46

    You can do it through scope resolution operator ::

    Something like this:

    pBase->Base::foo()
    
    0 讨论(0)
  • 2020-12-18 20:58
    pBase->Base::foo()
    
    0 讨论(0)
  • 2020-12-18 21:02

    Both responses above are correct...But be careful, if you need to do that, maybe you have a big problem about the conception or the design...

    0 讨论(0)
提交回复
热议问题