Function overloading is an important concept in C++. Sometimes, we want to use the same function name but have different functions to work on different data types or a different number of types. This is useful as the client can choose the correct function based on its needs. C++ allows us to do this by using function overloading.
In this recipe, we will learn how to overload a function:
Open Visual Studio.
Create a new C++ project.
Select a Win32 Console Application.
Add source files called
main.cpp
,Cspeed.h
, andCspeed.cpp
.Add the following lines of code to
main.cpp
:#include <iostream> #include <conio.h> #include "CSpeed.h" using namespace std; //This is not overloading as the function differs only //in return type /*int Add(float x, float y) { return x + y; }*/ int main() { CSpeed speed; cout<<speed.AddSpeed...