Open In App
Related Articles

Difference between virtual function and inline function in C++

Improve Article
Improve
Save Article
Save
Like Article
Like

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.

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 used to 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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 18 Jan, 2023
Like Article
Save Article
Previous
Next
Similar Reads