How to access protected method in base class from derived class?

后端 未结 6 489
孤街浪徒
孤街浪徒 2020-12-17 22:18

Here is a sample of code that annoys me:

class Base {
  protected:
    virtual void foo() = 0;
};

class Derived : public Base {
  private:
    Base *b; /* I         


        
6条回答
  •  醉梦人生
    2020-12-17 22:51

    Normally, you would do it using Base::foo(), which refers to the base class of the current instance.

    However, if your code needs to do it the way you're trying to and it's not allowed, then you'll need to either make foo() public or make Derived a friend of Base.

提交回复
热议问题