C++ Programming

C++ – Inline Function and Its Use

To minimize the time, an inline function is used. When there are only two or three statements, an inline f() is used. The f() is copied into the main function after it is called.

You must place the keyword inline before the function name and define the function before calling it. The compiler ignores the inline qualifier if the defined function is longer than a line. Even without using the inline specifier, a function definition in a class definition is an inline f() definition.

usingnamespace std;
intsubtraction (int a, int b)
return (a-b);

Drawbacks: Situations, where this function doesn’t work, are,

  1. If a function contains a static variable. 
  2. If the inline f() is recursive. 
  3. For function returning values, if loop, switch, or not exist. 
  4. For function non-returning values it returns statements that exist.

Back to top button