本文介绍了几个级别的基类会减慢c ++中的类/结构吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 有几个级别的基类会减慢类吗?多重继承会减慢一个类吗? 解决方案非虚函数调用在运行时完全没有性能损失,根据c ++的口头禅,你不应该支付你不使用的。 在虚函数调用中,无论多少级别的继承或基类的数量,通常都需要支付额外的指针查找。 当然这是所有的实现定义。 编辑:如在别处指出的,在一些多继承场景中,需要调整'this'打电话。 Raymond Chen描述了COM对象的如何工作。基本上,在从多个基址继承的对象上调用虚函数可能需要额外的减法和在虚拟调用所需的额外指针查找之上的jmp指令。 Does having several levels of base classes slow down a class? A derives B derives C derives D derives F derives G, ...Does multiple inheritance slow down a class? 解决方案 Non-virtual function-calls have absolutely no performance hit at run-time, in accordance with the c++ mantra that you shouldn't pay for what you don't use.In a virtual function call, you generally pay for an extra pointer lookup, no matter how many levels of inheritance, or number of base classes you have.Of course this is all implementation defined.Edit: As noted elsewhere, in some multiple inheritance scenarios, an adjustment to the 'this' pointer is required before making the call. Raymond Chen describes how this works for COM objects. Basically, calling a virtual function on an object that inherits from multiple bases can require an extra subtraction and a jmp instruction on top of the extra pointer lookup required for a virtual call. 这篇关于几个级别的基类会减慢c ++中的类/结构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-19 13:40