内联虚函数 [英] inline virtual function

查看:105
本文介绍了内联虚函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,我的理解是虚函数可以内联,但通常,内联的提示被忽略。看来内联虚拟函数没有太大的意义。

In C++, my understanding is that virtual function can be inlined, but generally, the hint to inline is ignored. It seems that inline virtual functions do not make too much sense.

是不是这样?

一个内联虚函数是好的情况?

Can anybody give a case in which an inline virtual function is good?

推荐答案

在正常情况下,虚函数将通过指针一个函数(包含在类'vtable中)。在这种情况下,如果编译器可以静态地确定函数将被调用的实际类型,而不仅仅是它必须是X类或从X派生的东西,那么虚函数调用只能被内联生成。

Under normal circumstances, a virtual function will be invoked via a pointer to a function (that's contained in the class' vtable). That being the case, a virtual function call can only be generated inline if the compiler can statically determine the actual type for which the function will be invoked, rather than just that it must be class X or something derived from X.

内联虚函数的主要时间是有意义的,如果你有一个性能关键的情况,并且知道一个类将被频繁使用,允许编译器确定实际类型静态的(并且至少一个目标编译器通过指针优化调用)。

The primary time an inline virtual function makes sense is if you have a performance critical situation, and know that a class will frequently be used in a way that allows the compiler to determine the actual type statically (and at least one target compiler optimizes out the call via pointer).

这篇关于内联虚函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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