Coupon Accepted Successfully!

Outside Member Function As Inline

In Chapter 7, we learned how inline mechanism is useful for small function. It is good practice to declare function prototype inside the class and definition outside the class. The inline mechanism reduces overhead relating to access the member function. It provides better efficiency and allows quick execution of functions. An inline member function is similar to macros. Call to inline function in the program, puts the function code in the caller program. This is known as inline expansion. Inline functions are also called as open subroutines because their code is replaced at the place of function call in the caller function. The normal functions are known as closed subroutines because when such functions are called, the control passes to the function.

By default, all member functions defined inside the class are inline function. The member function defined outside the class can be made inline by prefixing the keyword inline to function declarator as shown in Figure.

Inline function outside the class

The inline is a keyword and acts as function qualifier. The return type is functions return type; that is the function returns values of this type. The class name is the name of class that the function belongs to. Scope access operator separates class name and function name. The signature means argument list passed function. The following program illustrates inline function outside the class.

8.9 Write a program to make an outside function as inline.


Explanation: The above program is same as last one. The only difference is that the function show() is defined as inline outside the class. The function declarator is as follows inline void item::show().

Test Your Skills Now!
Take a Quiz now
Reviewer Name