Various types of Function overloading (compile time polymorphism / static binding)

Polymorphism means same entity behaving differently at different times. Compile time polymorphism is also called as static binding. Compile time or static binding means Function body is bind to the function call at compile time itself.  In C++ compile time polymorphism can be achieved using Function overloading and operator overloading.

Function overloading

Function overloading means, having multiple functions with same names. So how compiler does distinguishes between the multiple functions with same names.  In function loading multiple functions can have same name but they differ on number of parameters order of parameters and type of parameters.

Number of parameters

Order of parameters:

Types Of Parameters:


Functions cannot be overloaded based on function return type, as it may cause ambiguity. Compiler will give an error in this case.

Here its not possible to know which function body to be executed.

Overloading with Const member function :

There is another type of overloading, however it’s different than normal overloading and we can say its special.

We can declare a const member function which can be called on constant objects and it guarantess that it will not modify any member data.

Function Overloading with templates:

This is again special type of overloading; usually we have multiple functions declared with same name. However in templates we have just single function. At compile time based on parameter passed to function in angle brackets a data type specific template function Is generated. In the object code we have three different functions one for each int, char,float.

Leave a Reply