Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Difference between virtual function and inline function in C++

  • Last Updated : 27 Aug, 2020

Virtual function: Virtual function is a member function which is declared within a base class and is redefined by a derived class.

Inline function: Inline function is a normal function which is defined by the keyword inline, it is a short function which is expanded by the compiler and its arguments are evaluated only once.

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

The syntax of defining the function inline in C++ is:

inline return-type function-name(parameters)
    // function code

Difference between virtual function and inline function are as follows:

Virtual function

Inline function

1. Virtual function must be declared in public section of class.1. Inline function is a normal function which is defined by the keyword inline.
2. Virtual function cannot be static.2. Inline function can also be non-static.
3. Virtual function is defined in base class.3. Inline function are the short length functions that are automatically made the inline functions without using the inline keyword inside the class.
4. Virtual function are decrease the efficiency of code.4. Inline function are used to increase the efficiency of code.
5. Virtual function is to run time polymorphism.5. Inline function is to compile time polymorphism.
6. Virtual function may consists of virtual destructor but it cannot have a virtual constructor. 6. Inline function can also consist of inline constructor.
7. Virtual may use for dynamic linkage.7. Inline function is used to reduce the function call overhead.
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!