关于多重继承

发布于 2024-08-22 04:04:32 字数 60 浏览 3 评论 0原文

谁能解释一下

为什么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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

药祭#氼 2024-08-29 04:04:32

首先,一个小修正: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.

茶花眉 2024-08-29 04:04:32

从有关 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文