C++ inline Keyword
Example
Create an inline function:
inline int myFunction(int x, int y) {
return x + y;
}
int main() {
cout << myFunction(5, 3);
return 0;
}
Definition and Usage
The inline keyword suggests to the compiler that the code of a function should be inserted where the function is called. This can make a small function run a little faster, because the program does not have to jump to the function and back.
It is only a suggestion. The compiler decides for itself if it inserts the code or not.
inline also lets you define a function in a header file (a file that is included in other files) without errors.
Related Pages
Read more about functions in our C++ Functions Tutorial.