INLINE FUNCTIONS

C++ inline function is an effective concept which is commonly used with classes. If a function is inline, the compiler stores a copy of the code of the function at every point exactly where the function is called at compile time.Any kind of change to an inline function might require all clients of the function to be recompiled simply because compiler might need to change all the code once again elsewhere it will continue with old functionality.
To inline a function, place the keyword inline before the function name and define the function before any calls are made to the function. The compiler may neglect the inline qualifier in case defined function is a lot more than a line.A function definition in a class definition is an inline function definition, possibly without using the inline specifier.

So how exactly does this make the program execute quicker? Simple, function calls are merely much more time taking than writing all of the code without functions. To go through your program and exchange a function you have implemented 100 times with the code from the function would be time consuming not too bright. Obviously, by using the inline function to switch the function calls with code you will additionally increase the size of your program.

Simple example of inline function:



#include <iostream>

using namespace std;

inline void hello()
  cout<<"hello";
}
int main()
{
  hello(); //Call it like a normal function...
  cin.get();
}


FUNCTION OVERLOADING


An overloaded declaration is a declaration which had been declared with similar initials just as a earlier declared declaration in a similar scope , except for that the two declarations include distinct arguments as well as undoubtedly distinct definition ( implementation ) .Function overloading means two or more functions can have the same name but either the number of arguments or the data type of arguments has to be different, also note that return value has no role because function will return a value when it is called and at compile time we will not be able to determine which function to call.

Whenever you call up an overloaded function or operator , the compiler signifies the preferred definition to utilize by comparing the argument categories you employed to call the function or even operator with the parameter kinds specified in the definitions . The method of selecting the most appropriate overloaded function or operator is called overload resolution .



Simple example showing function overloading:



#include <iostream>

using namespace std;


/* Number of arguments are different */


void display(char []);  // print the string passed as argument

void display(char [], char []);

int main()

{
   char one[] = "C programming";
   char second[] = "C++ programming";

   display(one);

   display(one, second);

   return 0;

}

void display(char v[])

{
   cout << v << endl;
}

void display(char v[], char m[])

{
   cout << v << endl << m << endl;
}


0 comments to "INLINE FUNCTION AND FUNCTION OVERLOADING"

Post a Comment

Powered by Blogger.