C++C++11C++14C++17Introduction to C++Learn C++

Learn C++ Inheritance :: Hybrid Inheritance

Let’s remember that, Object Oriented Programming (OOP) is a way to integrate with objects which can contain data in the form (attributes or properties of objects), and code blocks in the form of procedures (methodsfunctions of objects). These attributes and methods are variables and functions that belong to the class, they are generally referred to as class members. In C++, classes have members (attributesmethods) and we should protect each member inside this class.

The Inheritance is one of the most important concept in object-oriented C++ programming as in other features of Classes. Inheritance allows us to define a class in terms of another class, and it makes easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time. Inheritance implements the relationship between classes. For example, a rectangle is a kind of shape and ellipse is a kind of shape etc.

Do you want to learn what is Hybrid Inheritance ? How we can use Inheritance in Hybrid from in an example ?

Hybrid Inheritance, it also is called Multipath Inheritance, is implemented by combining more than one type of inheritance. For example Hybrid Inheritance might be composed with derived classes with multiple base classes and these base classes have one common base class.

Here is a Hybrid Inheritance example below,

Let’s explain this with an example below;

In this example elephant object has only weight property but eagle has both weight and wingwidth properties. Please see how we declared both Mammal and Bird classes.

Get started building powerful apps with C++Builder!

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?

C++C++14C++17C++20Learn C++

What Are The C++14 Features Removed From C++17?

C++C++11C++14C++17C++20Learn C++Syntax

What is the conjunction (std::conjunction) metafunction in C++?

Worth reading...
Learn about Object Oriented Programming, Introduction to OOP