开发者

Hybrid Inheritance Example

开发者 https://www.devze.com 2023-01-08 05:57 出处:网络
Can anyone suggest any real life example of Hybrid inheri开发者_如何学Gotance?Hybrid Inheritance is a method where one or more types of inheritance are combined together. I use Multilevel inheritance

Can anyone suggest any real life example of Hybrid inheri开发者_如何学Gotance?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消