“虚拟"是什么意思?在“类 Foo:公共虚拟栏"中与“virtual void frob()"相反? [英] What does it mean when "virtual" is in "class Foo : public virtual Bar" as opposed to "virtual void frob()"?

查看:23
本文介绍了“虚拟"是什么意思?在“类 Foo:公共虚拟栏"中与“virtual void frob()"相反?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当virtual"在class Foo : public virtual Bar"而不是virtual void frob()"中是什么意思?

What does it mean when "virtual" is in "class Foo : public virtual Bar" as opposed to "virtual void frob()"?

对于给定的方法,有 8 种情况源于以下三个位置中虚拟的存在或不存在.

For a given method there are 8 cases stemming from the presence or absence of virtual in the following three locations.

  1. 超类的函数.
  2. 这个类的继承链.
  3. 此类函数.

我想我了解数字 1 和数字 3 如何相互作用,但数字 2 似乎多余.是吗?我不明白什么?

I think I understand how numbers 1 and 3 interact but number 2 seems redundant. Is it? What am I not understanding?

推荐答案

那是 虚拟继承,当你知道你将进行多重继承时,你就会这样做.该页面更详细.

That's virtual inheritance, you do it when you know you'll be doing multiple inheritance. That page goes into way more detail.

这篇关于“虚拟"是什么意思?在“类 Foo:公共虚拟栏"中与“virtual void frob()"相反?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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