Answer to Question #24197 in C++ for Nourh

Question #24197
What does it mean to overload a function? What is an advantage of doing so?
1
Expert's answer
2013-02-13T11:50:47-0500
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS