开发者

Hybrid Inheritance Example

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜