关于多重继承
谁能解释一下
为什么c#不支持多重继承,而c++支持多重继承?怎么可能? C++如何支持?
Can anyone explain me
why c# not supporting multiple inheritance since c++ supporting multiple inheritance ? how it is possible ? How c++ supports ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,一个小修正:C# 确实支持多个接口继承。它不支持多个实现继承。
不支持 MI 的两个重要原因是:
很可能您可以通过多接口继承执行您想要的操作。
它给编译器实现增加了很多复杂性。
在我看来,在许多情况下,语言中多重继承的可用性导致该功能经常被滥用。当诸如组合之类的东西也可以做同样的事情时,单继承已经不必要地融入了许多类层次结构中。
First, a small correction: C# does support multiple interface inheritance. It doesn't support multiple implementation inheritance.
The two big reasons MI isn't supported are:
Chances are good that you can do what you want with multiple interface inheritance anyway.
It adds a lot of complexity to the compiler implementation.
IMO, in many cases, the availability of multiple inheritance in a language causes that feature to be frequently abused. Single inheritance already gets wedged into a lot of class hierarchies unnecessarily when something like composition would do just as well.
从有关 C# 常见问题的 MSDN 博客中,您可以找到此答案。还有这个高度评价的 Stack Overflow 问题。
From an MSDN blog on C# frequently asked questions you can find this answer. There is also this highly rated Stack Overflow question.