C++ OOP Inheritance
- Base and Derived Classes
class derived-class: access-specifier base-class
# Inheritance
- public inheritance makes
publicmembers of the base classpublicin the derived class, and theprotectedmembers of the base class remainprotectedin the derived class. - protected inheritance makes the
publicandprotectedmembers of the base classprotectedin the derived class. - private inheritance makes the
publicandprotectedmembers of the base classprivatein the derived class.
class Base {
public:
int x;
protected:
int y;
private:
int z;
};
class PublicDerived: public Base {
// x is public
// y is protected
// z is not accessible from PublicDerived
};
class ProtectedDerived: protected Base {
// x is protected
// y is protected
// z is not accessible from ProtectedDerived
};
class PrivateDerived: private Base {
// x is private
// y is private
// z is not accessible from PrivateDerived
}