When to use C++ private inheritance over composition?

后端 未结 3 2067
礼貌的吻别
礼貌的吻别 2020-12-01 21:34

Can you give me a concrete example when is preferable to use private inheritance over composition? Personally, I will use composition over private inheritance, but there mig

3条回答
  •  误落风尘
    2020-12-01 21:58

    private inheritance is typically used to represent "implemented-in-terms-of". The main use I have seen is for mixins using private multiple inheritance to build up a child object with the proper functionality from the various mixin parents. This can also be done with composition (which I slightly prefer) but the inheritance method DOES allow you to use using to expose some parent methods publicly, and allows for a slightly more convenient notation when using the mixin methods.

提交回复
热议问题