When to use C++ private inheritance over composition?

后端 未结 3 2059
礼貌的吻别
礼貌的吻别 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:37

    Scott Meyers in "Effective C++" item 42 says

    "Only inheritance gives access to protected members, and only inheritance allows for virtual functions to be redefined. Because virtual functions and protected members exist, private inheritance is sometimes the only practical way to express an is-implemented-in-terms-of relationship between classes."

提交回复
热议问题