Contenido del Curso
C++ Intermediate | Mobile-Friendly
C++ Intermediate | Mobile-Friendly
Overloading
Function overloading - creating functions with the same names and different parameters. It’s often used when you want to apply the same functionality to variables of various types.
For example, let’s create the function printVar()
, which prints the variable:
Hmm, and what should we do if we want to print the string or double variable? Instead of creating another function, let’s overload this one. Here we overload the printVar()
function to work for int, double, and string:
Now we can use printVar()
to output the variable's type of int, double, and string. Pay attention that the declaration of the overloaded functions must differ from each other by the types of arguments.
¡Gracias por tus comentarios!