Article by: Manish Methani
Last Updated: October 17, 2021 at 10:04am IST
To clean up the code we write functions outside the class and this is best way to write any object oriented code. So why Inline Function ?. When we declare any function as inline then while compilation, compiler will replace that call of a function with the exact code whic you had written outside of that class.
In this example , compiler will replace the statement ,
inline void display();
with
void Game :: display() { cout<
Benefit of this inline function is to increase the execution speed of a program . By writing inline it skips the step of function call which actually takes overhead in memory and replaces that line with actual code. So in this way code looks cleaned plus memory saving :)
#include using namespace std; class Game { public: int abc; Game() { abc = 5; } inline void display(); }; void Game :: display() { cout<
5