bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/C++/C++ Classes
C++•C++ Classes

C++ Multilevel Inheritance

Multilevel Inheritance

A class can also be derived from one class, which is already derived from another class.

In the following example, MyGrandChild is derived from class MyChild (which is derived from MyClass ).

Example

// Base class (parent) class MyClass { public: void myFunction() { cout << "Some content in parent class." ;
}
};
// Derived class (child) class MyChild: public MyClass {
};
// Derived class (grandchild) class MyGrandChild: public MyChild {
};
int main() {
  MyGrandChild myObj;
  myObj.myFunction();
  return 0;
}

Previous

C++ Inheritance

Next

C++ Multiple Inheritance

This chapter

Overview
17

Lessons

49m

Read time

1. C++ OOP2. C++ Classes and Objects3. C++ Class Methods4. C++ Constructors5. C++ Constructor Overloading6. C++ Access Specifiers7. C++ Encapsulation8. C++ The Friend Keyword9. C++ Inheritance10. C++ Multilevel Inheritance11. C++ Multiple Inheritance12. C++ Inheritance Access13. C++ Polymorphism14. C++ Virtual Functions15. C++ Templates16. C++ Files17. C++ Date and Time