inline function in c++
TRANSCRIPT
Yogi’s Guide to
C++Yogi’s Guide
toC++
Inline Functions
Yogendra Pal
www.learnbywatch.com | [email protected]
At the end of this tutorial you will be able to • Explain how does function call happens in computer memory.
• Explain inline function.
• Explain the difference between inline function and regular function.
• Identify inline functions from a given c++ program.
• Write inline functions in c++ program.
• Explain when a function qualify for inline function.
www.learnbywatch.com | [email protected]
Function call in detail
www.learnbywatch.com | [email protected]
Inline Function• Call to an inline function is replaced by the function code.
• Run faster than regular functions.
• Consume more memory than regular functions.
www.learnbywatch.com | [email protected]
Inline function creation• Preface the function declaration with the keyword inline, OR
• Preface the function definition with the keyword inline.
inline return_type function_name(argument_list);
inline return_type function_name(argument_list){ statements;}
OR
www.learnbywatch.com | [email protected]
Inline Function at Run Timeinline void function_name(argument_list){ statement_1; statement_2;}
int main(){ function_name(); cout << “new line”; function_name();}
int main(){ statement_1; statement_2; cout << “new line”; statement_1; statement_2;}
At run time
www.learnbywatch.com | [email protected]
Inline function in Class• Write function definition inside class declaration to make it inline.
• Make a function inline using inline keyword outside class declaration.
Yogi’s Guide to
C++Yogi’s Guide
toC++
Ask your questionsto learn better
Yogendra Pal
www.learnbywatch.com | [email protected]