Suppose I have a base and derived class:
class Base
{
public:
virtual void Do();
}
class Derived:Base
{
public:
virtual void Do();
}
int main()
{
Derived sth;
sth.Do(); // calls Derived::Do OK
sth.Base::Do(); // ERROR; not calls Based::Do
}
as seen I wish to access Base::Do through Derived. I get a compile error as "class Base in inaccessible" however when I declare Derive as
class Derived: public Base
it works ok.
I have read default inheritance access is public, then why I need to explicitly declare public inheritance here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…