Can virtual functions be inlined?
Virtual functions are used to achieve runtime polymorphism or say late binding or dynamic binding. Inline functions are used for efficiency. The whole idea behind the inline functions is that whenever inline function is called code of inline function gets inserted or substituted at the point of inline function call at compile time. Inline functions are very useful when small functions are frequently used and called in a program many times.
By default all the functions defined inside the class are implicitly or automatically considered as inline except virtual functions (Note that inline is a request to the compiler and its compilers choice to do inlining or not).
Whenever virtual function is called using base class reference or pointer it cannot be inlined (because call is resolved at runtime), but whenever called using the object (without reference or pointer) of that class, can be inlined because compiler knows the exact class of the object at compile time.
This article is contributed by Meet Pravasi. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above