Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Overloading | Functions
C++ Intermediate | Mobile-Friendly
course content

Kursinnehåll

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

book
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:

python

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:

python

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.

question-icon

Fill gaps:

Function overloading - creating functions with thenames and parameters.

Click or drag`n`drop items and fill in the blanks

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 11

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

course content

Kursinnehåll

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

book
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:

python

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:

python

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.

question-icon

Fill gaps:

Function overloading - creating functions with thenames and parameters.

Click or drag`n`drop items and fill in the blanks

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 11
Vi beklagar att något gick fel. Vad hände?
some-alt