Overloaded Function Examples

We can write several functions that all share the same name. This is called overloading a function.
int cube(int number)
{
 return number * number * number;
}

long cube(long number)
{
 return number * number * number;
}

float cube(float number)
{
 return number * number * number;
}

double cube(double number)
{
 return number * number * number;
}
Example calls:
int i;
long l
float f;
double d;
i = cube(2);        // calls cube(int), i is 8
l = cube(100L);     // calls cube(long), l is 1000000L
f = cube(2.5f);     // calls cube(float), f is 15.625f
d = cube(2.34e25);  // calls cube(double), d is
                    //   1.2812904e+76
Previous page
Next page

Back to Index
Back to Outline