何时可能是多重继承是唯一合理的解决方案? [英] When might multiple inheritance be the only reasonable solution?

查看:145
本文介绍了何时可能是多重继承是唯一合理的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要清楚,我不是问是否/为什么多重继承是好还是坏。我已经听到了辩论双方的很多争论。

To be clear, I'm not asking if/why multiple inheritance is good or bad. I've heard a lot of arguments from both sides of that debate.

我想知道是否有任何种类的设计问题或C ++中的场景,其中多重继承是实现某种事情的唯一方法,或者至少是所有其他替代方法的最佳方法,因为考虑其他事情是没有意义的。

I'm wondering if there is any kind of design problem or scenario in C++ in which multiple inheritance is either the only way to accomplish something, or at least is the most optimal way over all other alternatives to the point that it wouldn't make sense to consider anything else.

显然,这个问题不适用于不支持多重继承的语言。

Obviously, this question doesn't apply to languages that don't support multiple inheritance.

推荐答案

a href =http://en.wikipedia.org/wiki/Policy-based%5Fdesign>没有多重继承的基于策略的设计。因此,如果基于策略的设计是解决您的问题的最优雅的方式,那么意味着您需要多个继承来解决您的问题,而非所有其他选项。

You can't do policy-based design without multiple inheritance. So if policy-based design is the most elegant way to solve your problem, than that means you need multiple inheritance to solve your problem, over all other options.

如果不被滥用(如任何语言中的一切),继承可以是非常有用的。

Multiple-inheritance can be very useful if it's not misused (like everything, in any language).

这篇关于何时可能是多重继承是唯一合理的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆