June 2025
Intermediate to advanced
1093 pages
33h 24m
English
When a class inherits something from a predecessor, you normally bring in the base class with public:
class Base {};class Derived : public Base { ...};
This suggests that there are other possibilities. protected and private are also possible here, and this affects the visibility of the inherited fields and methods.
// https://godbolt.org/z/eKbK39nG1class Base {public: int xPublic = 1;protected: int xProtected = 2;private: int xPrivate = 3;};class DerivedPublic : public Base { // xPublic becomes 'public' // xProtected becomes 'protected' // xPrivate is not visible here};class DerivedProtected : protected Base { // xPublic becomes 'protected' // xProtected becomes 'protected' // xPrivate is not visible here};class ...
Read now
Unlock full access