Explain Inline member functions in C++


While creating an application, partitioning a class into an interface (.h file) and implementation (.cpp file) is a good rule to follow. However, sometimes for the sake of efficiency we need to include the implementation with the interface. In such a case instead of writing definition of member functions in the class declaration itself it is better to follow the method as given below:

//In abc.h file

class Abc

{

public :

// function declarations

} ;

inline void Abc::f1( int i )

{

// Code

}

inline int Abc::f2( )

{

//code

}

In the above code we have used the inline keyword which directs the compiler to replace the function call with actual code of function and parameters substituted appropriately. This method avoids overhead of function call and results in significantly faster program.

This entry was posted in C++ and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>