Hybrid Inheritance Example

Can anyone suggest some real example of hybrid inheritance?

+3
source share
1 answer

Hybrid inheritance is a method in which one or more types of inheritance are combined together. I use multi-level inheritance + single inheritance at almost all times when I need to implement an interface.

struct ExtraBase { void some_func(); };
struct Base : public ExtraBase {};
struct Derived : public Base, public IUnknown {};

...
Derived x = new Derived;
x->AddRef();
x->some_func();

Here is an example in which it Deriveduses some_funcfrom ExtraBase(multi-level inheritance), and Deriveduses AddReffrom IUnknown, which is inherited once. Of course, this is not production code, but the idea is close to it.

+1

Source: https://habr.com/ru/post/1755503/


All Articles