C ++中的虚拟继承使用/技巧 [英] Virtual inheritance in C++ usages/tricks

查看:147
本文介绍了C ++中的虚拟继承使用/技巧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有在专业软件中使用它,即使在我们的商店和其他我已经工作,我们设计大型系统。我唯一一次搞砸虚拟继承的时候是在一家公司的面试中。尽管如此,我在下班后玩它。

I've never used it in the professional software even though in our shop, and others I have worked for, we design large scale systems. The only time I messed with virtual inheritance was during my interview in a company. Nonetheless, I played with it during afterhours.

你们用吗?你理解它是如何工作的深度(如何最流行的编译器供应商实现它)?我真的想知道如何在专业软件中使用,如果有的话。

Do you guys use it? Do you understand how it works in depth (how most popular compiler vendors implement it)? I would really like to know how it is used in professional software, if at all. Tricks and tips would be appreciated, too.

对我来说,虚拟继承只是一个臭名昭着的钻石问题的解决方案。因此,它从来没有在我们的软件中找到它的方式,因为我们在我们的架构MI没有导致钻石。

To me, virtual inheritance was just a solution to an infamous diamond problem. Hence, it never found its way in our software, as we don't have in our architecture MI resulting in the diamond.

感谢。

推荐答案

虚拟继承的主要观点是防止派生类继承不同上级类的多个副本。这可能发生在任何情况下,可能有多个继承 - 正如你正确地注意到,钻石问题,这就是说继承图是一个DAG而不是一个严格的树。

The main point with virtual inheritance is to prevent derived classes from inheriting multiple copies of different superior classes. This can occur in any case where there may be multiple inheritance -- as you correctly note, the "diamond problem", which is to say where the inheritance graph is a DAG instead of a strict tree.

C ++常见问题解答在一些细节。我也推荐C ++常见问题书;我曾经为作者工作,他们都很好。

The C++ FAQ goes into it in some detail. I'd also recommend the C++ FAQ Book; I used to work for the authors and they're quite good.

这篇关于C ++中的虚拟继承使用/技巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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