C++ Program using function overloading


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


void display(int){
    //statement
}

void display(int, int){
    //statement
}

Example: How to implement function overloading in C++

#include<iostream>
using namespace std;

class Test {
public:

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

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

int main() {

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

   return 0;
}

Output:

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