Exempting Individual Members
Sometimes we need to change the access level of a name that a derived class inherits. We can do so by providing a using declaration (§3.1, p. 82):
class Base {public: std::size_t size() const { return n; }protected: std::size_t n;};class Derived : private Base { // note: private inheritancepublic: // maintain access levels for members related to the size of the object using Base::size;protected: using Base::n;};
Because Derived uses private inheritance, the inherited members, size and n, are (by default) private members of Derived. The using declarations adjust the accessibility of these members. Users of Derived can access the size member, and classes subsequently derived from Derived can access ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access