views:

149

answers:

1

Can anyone suggest any real life example of Hybrid inheritance?

A: 

Hybrid Inheritance is a method where one or more types of inheritance are combined together. I use Multilevel inheritance + Single Inheritance almost at all time 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 where Derived uses some_func from ExtraBase (multilevel inheritance) and Derived uses AddRef from IUnknown which is inherited a single time. Surely it is not from a production code, but the idea is close to it.

Kirill V. Lyadvinsky
Should `Base` derive from `ExtraBase` in the code?
David Rodríguez - dribeas
Yes, fixed that.
Kirill V. Lyadvinsky
Can you give me some real life example where Hybrid inheritance is used?
Mayur
You have a class with multilevel inheritance and you need to implement some sort of callback interface - this is from real life.
Kirill V. Lyadvinsky