inline function in c++

8
Yogi’s Guide to C++ Yogi’s Guide to C++ Inline Functions Yogendra Pal

Upload: learn-by-watch

Post on 15-Jan-2017

664 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Inline function in C++

Yogi’s Guide to

C++Yogi’s Guide

toC++

Inline Functions

Yogendra Pal

Page 2: Inline function in C++

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.

Page 3: Inline function in C++

www.learnbywatch.com | [email protected]

Function call in detail

Page 4: Inline function in C++

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.

Page 5: Inline function in C++

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

Page 6: Inline function in C++

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

Page 7: Inline function in C++

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.

Page 8: Inline function in C++

Yogi’s Guide to

C++Yogi’s Guide

toC++

Ask your questionsto learn better

Yogendra Pal

www.learnbywatch.com | [email protected]