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

后端 未结 6 516
孤街浪徒
孤街浪徒 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:58

    How do you access to the protected overrided function?

    --- from where?

    You can access a protected member only via inheritance (apart from the methods of the same class). Say for example you have a class Derived1 which inherits from Derived, then objects of Derived1 can call foo().

    EDIT: MSDN article on protected access specifier.

提交回复
热议问题