Built-in functions
In C ++, a macro is nothing more than a built-in function. So now macros are under compiler control.
- Important : if we define a function inside a class, it will automatically become Inline
The Code Inline function is replaced where it is called, so this reduces the overhead of calling the function.
In some cases, the insert function may not work, for example,
If a static variable is used inside an inline function.
If the function is complicated.
If a recursive function call
If the address of the function is taken implicitly or explicitly
A function defined outside the class, as shown below, may become inline
inline int AddTwoVar(int x,int y); //This may not become inline inline int AddTwoVar(int x,int y) { return x + y; } // This becomes inline
A function defined inside a class also becomes inline
// Inline SpeedMeter functions class SpeedMeter { int speed; public: int getSpeed() const { return speed; } void setSpeed(int varSpeed) { speed = varSpeed; } }; int main() { SpeedMeter objSM; objSM.setSpeed(80); int speedValue = A.getSpeed(); }
Here the getSpeed and setSpeed functions will become inline
Saurabh Raoot Aug 10 '18 at 12:13 2018-08-10 12:13
source share