I am a beginner and was using the 'Teach Yourself C++ in 24 Hours' Book. I couldnt understand how overloaded functions worked. Could someone explain by providing an answer to the following question:
Write a program that can calculate the average of two integers, two long integers
or two floating-point values using an overloaded function named
average().
Any additional help will also be very helpful..
Thanks
#include <iostream>
int function1 (int);
int function1 (int,int); /* overloading a function means using the same name but
different parameters (or types) like what xander said */
{
int variable1,variable2;
variable1 = 0;
variable2 = 0;
function1(variable1); //the compiler will know you're calling the function with 1 parameter
function1(variable1,variable2); /* the compiler will know you're calling the function with 2 parameters */
return 0;
}
int function1(int variable1)
{
//code goes here
return 0;
}
int function1 (int variable1, int variable2)
{
//code goes here
return 0;
}