#include <stdio.h> //for printf
//------------------------------------------
// FUNCTION OVERLOADING: Its just convenient
//------------------------------------------
//------------------------------------------
// First Function
//------------------------------------------
void OverloadingExample(char * String)
{
/*
First off we have a very unassuming function. It takes a character pointer as a
parameter and displays it. Nothing unusual here.
*/
printf(String);
}
//------------------------------------------
// Second Function (of same name)
//------------------------------------------
void OverloadingExample()
{
/*
Here we have our first overloaded function. It has the same name and type as the
previously declared function, but takes no paramters. When there is a function
call to OverloadingExample, and there are no arguments passed in, this function
will be called instead of the origional.
*/
printf("OverloadingExample() Overloaded Function called without parameter.\n");
}
//------------------------------------------
// Third Function (of same name)
//------------------------------------------
void OverloadingExample(int Number)
{
/*
With this example we see that we can overload a function as many times as we want.
This overloaded function takes a parameter of type int. If OverloadingExample is
called with a character pointer supplied, the initial function is executed. If it is called
without any argument at all, the second function is executed. Now, if it is called with
an integer as its argument, this function will be executed.
*/
printf("OverloadingExample() Overloaded Function called with integer parameter: %i\n", Number);
}
//------------------------------------------
// MAIN
//------------------------------------------
int main(void)
{
OverloadingExample("Calling OverloadingExample() function with parameter...\n");
OverloadingExample();
OverloadingExample(10);
/*
Overloading is simple in operation. It is basically no different from having additional
functions with different names. The overloaded functions are treated no differently
once your program is compiled than any other function. In fact, once compiled, there
_is_ no difference. Overloaded functions are a convenience only.
*/
return 0;
}