The Wayback Machine - https://web.archive.org/web/20120327102524/http://en.cppreference.com:80/w/cpp/language/inline

inline specifier

From cppreference.com

Jump to: navigation, search

[edit] Syntax

inline function_declaration

[edit] Description

The inline keyword is a hint given to the compiler to perform an optimization. The compiler has the freedom to ignore this request.

If the compiler inlines the function, it replaces every call of that function with the actual body (without generating a call). This avoids extra overhead created by the function call (placing data on stack and retrieving the result) but it may result in a larger executable as the code for the function has to be repeated multiple times. The result is similar to function-like macros

The function body must be visible in the current translation unit.

Class methods defined inside the class body are implicitly declared inline.

[edit] Example

inline int sum(int a, int b) 
{
    return (a + b);
}
 
int c = sum(1, 4);
// if the compiler inlines the function the compiled code will be the same as writing
int c = 1 + 4;
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
In other languages