本文介绍了保护继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么要定义和提出保护和私有继承?我理解一些情况下,可以使用私人继承,但不推荐。如何保护继承?
Why protected and private inheritance are defined and proposed? I understand some cases private inheritance could be used but it is not recommended. How about protected inheritance?
任何人都可以提供一种保护继承是一种选择的情况?
Can anyone offer me an situation in which protected inheritance is a choice?
很少看到这个。
非常感谢!
推荐答案
私人继承通常用于mixins - 其中人们继承从基类获取功能,而不是因为is-a继承。
Private inheritance is usually used for mixins---where people inherit to get functionality from the base class, rather than because of "is-a" inheritance.
保护继承也可以用于mixins,其中混合功能也可用于下游类。
Protected inheritance can also be used for mixins, where the mixed-in functionality is to be available to downstream classes too.
这篇关于保护继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!