Inline functions are an inline extension that is used to eliminate the time overhead of function calls. It is commonly used for frequently executed functions
If you need to perform an operation frequently, you can use inline to define it.
#include "stdafx.h" #include <Windows.h> #include <iostream> #include <fstream> #include < Shappmgr.h> #include <stdio.h>using namespace std;inline bool Isnumber (char ch) {return (ch >= ' 0 ') && ; (Ch <= ' 9 '));} int main () {char a;while ((a = Cin.get ()) = ' \ n ') {if (Isnumber (a)) {cout << "you have entered a number between 0-9" << Endl;} else {cout << "you have entered a number other than 0-9" << Endl;}} return 0;}
However, inline functions cannot contain complex keywords (such as while,switch), and if so, the compiler ignores these definitions and continues to produce the same calling code for the following calls.
Recursive functions cannot be used for inline functions,
In many cases, inline functions are limited to small, frequently called functions.
Inline functions and macro definitions
You can replace the inline function with:
inline int MAX (int a,int b) { return a>b?a:b}
Example
#include "stdafx.h" #include <Windows.h> #include <iostream> #include <fstream> #include < Shappmgr.h> #include <stdio.h>using namespace std;inline int Tobiger (int a, int b) {return a > B? a:b;} inline int Tosmall (int a, int b) {return a < b a:b;} int main () {int a = 10;int B = 11;cout << Tobiger (b) << endl;cout << Tosmall (A, b) << endl;a = a + a;cout << Tobiger (a++, b) << endl;cin.get (); return 0;}
Output:
11
10
20
C + + self-learning-inline functions