1#include<iostream>
2/* When a function will be called repetitively, The "inline" keyword is used for
3optimization. The inline function tells the compiler that every instance of
4this function should be replaced with the line or block of code in the body of the function;
5This makes the compiler skip the middle-man, the function itself!
6
7Important note: this method of optimization saves very little space, but it is still good practice.
8
9*********************************************************************
10* If this helped you, plz upvote! *
11* My goal is to make programming easier to understand for everyone; *
12* upvoting my content motivates me to post more! *
13* *
14*********************************************************************
15
16
17*/
18inline void PrintEverySecond(string str)
19{
20std::cout << str;
21
22int main()
23{
24string Message = "Inline!"
25PrintEverySecond(Message);
26}
27 // Unimportant note: this code obviously won't print every second since in isn't in a loop. This code is just a simple demo!
1A function specifier that indicates to the compiler that inline substitution
2of the function body is to be preferred to the usual function call
3implementation
1#include <iostream>
2
3using namespace std;
4
5inline int Max(int x, int y) {
6 return (x > y)? x : y;
7}
8
9// Main function for the program
10int main() {
11 cout << "Max (20,10): " << Max(20,10) << endl;
12 cout << "Max (0,200): " << Max(0,200) << endl;
13 cout << "Max (100,1010): " << Max(100,1010) << endl;
14
15 return 0;
16}
1Inline Member Functions (C++)
2A member function that is both declared and defined in the class member list is called an inline member function. Member functions containing a few lines of code are usually declared inline.
3