Hello All,
I can not understood what is function Overloading?
Please help me........


Your Regard
Sohel Rana
Bangladesh

Hello All,
I can not understood what is function Overloading?
Please help me........


Your Regard
Sohel Rana
Bangladesh

Hello, you can write in your program functions that will have the same name. When you call in your program one of these functions you have to make clear which function will be executed via the function's parameters. e.g. if i write two functions that will sum 2 integer and 2 double numbers then the prototype for each function will look like this:

int sum(int a, int b)

  double sum(double a, double b)

So if i pass integer parameters in function sum the first function will be executed, but if i pass double parameters then the second function will be executed..I hope i helped..

Function overloading is the process of writing multiple versions of the same function to operate differently based on the argument dataType(s) and/or argument count. Which version of the function gets called/executed depends on the arguments provided.

A common example is an "area" function from geometry. You can overload area() to work, for example, with both circles and rectangles:

//define constants
const double PI = 3.14159;

//function prototypes:
double area(double);         //prototype for area of circle
double area(double, double)  //prototype for area of right quadrilateral

//function calls:
double circleArea = area(2.5);
double rectArea = area(4.0, 5.0);

//function definitions:
double area(double radius) { //function calculates area of circle
  return (PI * radius * radius);
}

double area(double length, double width) { //area of right quadrilateral
  return (length * width);
}

Edited 6 Years Ago by Fbody: n/a

This article has been dead for over six months. Start a new discussion instead.