多重继承是邪恶的吗? [英] Is Multiple Inheritance Evil?

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

问题描述

可能重复:
多重继承的确切问题是什么?

Possible Duplicate:
What is the exact problem with multiple inheritance?

为什么在实现多个接口时多重继承被视为邪恶?尤其是当曾经认为接口仅仅是纯抽象类时?

Why is multiple inheritance considered to be evil while implementing multiple interfaces is not? Especially when once considers that interfaces are simply pure abstract classes?

(或多或少)的重复项多重继承的确切问题是什么?

(More or less) duplicate of What is the exact problem with multiple inheritance?, Multiple Inheritance in C#, and some others...

推荐答案

多重继承的常见问题是钻石问题".

The common problem with multiple inheritance is the "diamond problem".

  A
 / \
B   c
 \ /
  D

如果B和C都实现了A中的虚拟方法,那么在创建D时会得到哪个?

If a virtual method in A is implemented by both B and C, which one do you get when you create D?

这对接口不是问题的原因是因为接口没有实现,所以如果A/B/C都是接口,则D选择如何以适当的方式实现A方法.

The reason this isn't a problem with interfaces is because interfaces don't have implementations, so if A/B/C are all interfaces, then D chooses how to implement the A methods in whatever manner is appropriate.

这篇关于多重继承是邪恶的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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