Inline function in C++ is a powerful concept that is commonly used alongside classes. For an inline function, the compiler places a copy of the code of that function at each point where the function is called at the compile time.
In other for you to inline a function, do the following:
In cases where the defined function is more than a line, the compiler can ignore the inline qualifier.
Below are some of the features of inline functions:
Syntax:
inline return-type function-name(arguments)
{
return ( conditions );
}
Below is an example, that makes use of an inline function to return maximum of two numbers:
Example:
#include <iostream>
inline int Max(int x, int y)
{
return (x > y)? x : y;
}
// Main function for the program
int main( )
{
cout << "Max (30,40): " << Max(30,40) << endl;
cout << "Max (0,100): " << Max(0,100) << endl;
cout << "Max (700,10): " << Max(700,10) << endl;
return 0;
}