What is inline member function in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is inline member function in C++?

Please explain the function of 'Inline Member Function'? How does it works? What will happen if i use 'void' in place of 'inline'?

26th Feb 2018, 11:40 AM
Abdur Rahman
Abdur Rahman - avatar
1 Answer
+ 2
Inline functions are somewhat similar to Macros, if you have heard of them. In C++, when a functional is called, currently executing function is set aside by saving all the working variables to a stack, and start executing the calling function. There is a little bit of overhead in doing house keeping stuff like saving the context, switching the context to the new function and returning to the old context. Inline functions reduces this overhead. The C++ compiler tries to replace their code into the calling function itself so that the context switching time is reduced. Normally simple functions are declared inline and this is only a signal to the compiler to make it inline. It can decide whether to really expand the function inline or not. Functions with loops, and recursion are not candidates for replacing inline. For more info, http://www.cplusplus.com/articles/2LywvCM9/
26th Feb 2018, 12:06 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar