Suppose we have:
class Base
{
__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
virtualare called virtually – those can be inlined.Then,
__forceinlinewon’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.