Inheritance and inline?

I have read a lot lately and while inheriting inheritance (and virtual functions), I keep stumbling on the keyword "inline". Now I know that the built-in in the normal sense - the compiler can replace function calls with exact code. However, how many times I saw him mention inheritance, is there any special reason for using inline in inheritance? I do not understand why this is mentioned ...

What additional role does the built-in function inside inherited / derived classes / virtual functions?

+6
source share
1 answer

Yes, using built-in virtual functions is a waste of time. A virtual function must be called through a table of virtual functions, which consists of function pointers. A pointer cannot call an inline function. It must exist as a real function.

There are some exceptions. If the caller knows the exact type of object, he can completely skip the virtual function table.

Excessive use of the virtual keyword can lead to very slow code. If the compiler can embed and optimize three or four small function calls, with virtual functions, it must make the actual function calls without making any assumptions about the memory or registration status between calls.

+2
source

All Articles