What are access specifiers? Should I inherit with private, protected or public?

前端 未结 2 853
时光说笑
时光说笑 2020-11-22 07:42

I am confused about the meaning of access modifiers with respect to inheritance. What is the difference between inheritance involving the private, protect

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 08:28

    The explanation from Scott Meyers in Effective C++ might help understand when to use them:

    Public inheritance should model "is-a relationship," whereas private inheritance should be used for "is-implemented-in-terms-of" - so you don't have to adhere to the interface of the superclass, you're just reusing the implementation.

提交回复
热议问题