开发者

Will _forceinline virtual function from base class be __forceinlined in derived class without explicitly stating it?

Suppose we have:

class Base
{
开发者_StackOverflow__forceinline virtual int A() {return 1;}
}


class Derived: public Base
{
    int A() 
    {
        return 2;
    }
}

Function A in derived class is virtual without explicitly stating it. Will function A in derived class be also __forceinlined without explicitly stating it?


First, functions called virtually can't be inlined - the compiler needs to get to vtable pointer first to know which function to call. Not all functions marked virtual are called virtually - those can be inlined.

Then, __forceinline won't propagate to the derived class implementation - it's a non-standard compiler-specific keyword that has effect per function. So if you want to force inlining you have to apply the keyword again in the derived class function. Again it won't guarantee that all calls will be inlined.


this should be documented in the compiler you are using, but to me, an "inlineness" -- whether forced or not, is something that is not part of contract for inheritance. so, no it should not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜