Inline function(oops)

3
Inline function: Inline function is the optimization technique used by the compilers. It is a function which is declared using inline keyword or within the class. The function which is declared within the class is said to be inline function if it satisfies following conditions: -function should not have any return statements. -function should not be recursive function. -function length should be short. -function should not have any static variable. is considered as inline function by compiler. Inline function can only be requested to compiler, a user can only request to comlier to make a particular funtion as an inline function, its depend on the compiler

description

 

Transcript of Inline function(oops)

Page 1: Inline function(oops)

Inline function:

Inline function is the optimization technique used by the compilers. It is a function which is declared using inline keyword or within the class. The function which is declared within the class is said to be inline function if it satisfies following conditions:

-function should not have any return statements.

-function should not be recursive function.

-function length should be short.

-function should not have any static variable.

is considered as inline function by compiler.

Inline function can only be requested to compiler, a user can only request to comlier to make a particular funtion as an inline function, its depend on the compiler to make it as an inline function or not. An inline function is used to short the execution time. Its main task is that, it copy the body part of an inline function where it is called.

Its advantages are as under:

- It shorter the execution time.-  It does not require function calling overhead- It saves time.

Page 2: Inline function(oops)

Its disadvantages are as under:

- It increases the length of our file.- It may make our file unreadable.

e.g:

#include<iostream>

using namespace std;

class number

{

int n;

public:

void setdata()

{

n=10;

}

void display()

{

Cout<<n;

Page 3: Inline function(oops)

}

};

In above example, both of the functions will be considered as inline function by the compiler as it satisfies all conditions.