cpp/language/inline

The specifier, when used in a function's, declares the function to be an inline function.

A function defined entirely inside a, whether it's a member function or a non-member function, is implicitly an inline function.

Explanation
An inline function has the following properties:


 * 1) The definition of an inline function  must be reachable in the translation unit where it is accessed (not necessarily before the point of access).
 * 2) An inline function  with  (e.g. not declared ) has the following additional properties:
 * There may be of an inline function  in the program as long as each definition appears in a different translation unit and (for non-static inline functions ) all definitions are identical. For example, an inline function  may be defined in a header file that is included in multiple source files.
 * It must be declared in every translation unit.
 * It has the same address in every translation unit.

In an inline function,
 * Function-local static objects in all function definitions are shared across all translation units (they all refer to the same object defined in one translation unit).
 * Types defined in all function definitions are also the same in all translation units.

The original intent of the keyword was to serve as an indicator to the optimizer that inline substitution of a function is preferred over function call, that is, instead of executing the function call CPU instruction to transfer control to the function body, a copy of the function body is executed without generating the call. This avoids overhead created by the function call (passing the arguments and retrieving the result) but it may result in a larger executable as the code for the function has to be repeated multiple times.

Since this meaning of the keyword is non-binding, compilers are free to use inline substitution for any function that's not marked, and are free to generate function calls to any function marked. Those optimization choices do not change the rules regarding multiple definitions and shared statics listed above.