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.

Subscribe / Share

It's very calm over here, why not leave a comment?

Leave a Reply




Categories

Powered by Yahoo! Answers