Effective C++: discouraging protected inheritance?

前端 未结 5 672
北恋
北恋 2021-02-02 11:10

I was reading Scott Meyers\' Effective C++ (third edition), and in a paragraph in Item 32: Make sure public inheritance is \"is-a\" on page 151 he make

5条回答
  •  孤城傲影
    2021-02-02 11:38

    Yup, there aren't many uses for protected or private inheritance. If you ever think about private inheritance, chances are composition is better suited for you. (Inheritance means 'is-a' and composition means 'has-a'.)

    My guess is that the C++ committee simply added this in because it was very easy to do and they figured, "heck, maybe someone will find a good use for this". It's not a bad feature, it doesn't do any harm, just that no one has found any real use for it yet. :P

提交回复
热议问题