In a C++ language An inline function is similar to macros. Inline function is also called as open subroutine because their code is replaced at the place of function call in the caller function.
In a C++programming normal function are known as closed subroutine because when such function are called ,the control passed to the function.
inline function reduces the overhead of accessing the member function, increases the efficiency of program and allows quick execution of function.
Example of inline function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> using namespace std; class Demo { public: void show(); void display(); }; inline void Demo::show() // outside inline function { cout << "Inside Show"; } void Demo::display() // normal function { cout << "\n Inside display"; } int main() { Demo obj; obj.show(); obj.display(); } |
Output
1 2 | Inside Show Inside display |
Note:
1 Inline function used when the member function contains few statement.
2 If function takes more time to execute , then it must be declared inline. .