In C++, inheritance is a core feature that allows a class to derive properties and functionality from another class. There are three types of inheritance: public, protected, and private. Each type of inheritance affects the accessibility of the inherited members in different ways.
Public inheritance is the most common type used. When a class is derived publicly from a base class, as represented by the syntax `: public BaseClass`, it implies that:
- Public members of the base class remain public in the derived class.
- Protected members of the base class remain protected in the derived class.
- Private members of the base class are not accessible directly by the derived class.
In the example, `class Pet : public Dos` indicates that 'Pet' inherits from 'Dos' using public inheritance. Therefore, all the public members of 'Dos' are also public members in 'Pet', allowing them to maintain their visibility and accessibility.