What does it mean to overload a function? What is an advantage of doing so?
Overloading a function means that you implement functions with the same name
but with different numbers of parameters and/or parameter types.
#include <stdio.h>
void print_string(const char* str)
{
printf(str);
}
void print_int(int n)
{
printf("%d", n);
}
Overloading allows you to execute different tasks by one function
according to the input parameters. On the other side it allows you
to organize the functions performing similar operations with objects
of different types (as in the code above).
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++