C++ Program using function overloading


In this program, You will learn how to implement function overloading in C++.


void display(int)

void display(int, int)


Example: How to implement function overloading in C++

Run it Now
#include<iostream>
using namespace std;

class Test {
public:

   void display(int x) {
       cout << "The value of x is :" << x;
   }

   void display(int x, int y) {
       cout << "\nThe value of x is :" << x;
       cout << "\nThe value of y is :" << y;
   }
};

int main() {

   Test tt;
   tt.display(10);
   tt.display(20, 30);

   return 0;
}

Output:

The value of x is :10
The value of x is :20
The value of y is :30