Skip to content

Instantly share code, notes, and snippets.

@dibakarsutradhar
Created September 8, 2018 17:51
Show Gist options
  • Save dibakarsutradhar/b1a910f02fc4166cbe73b1c2e57bc30b to your computer and use it in GitHub Desktop.
Save dibakarsutradhar/b1a910f02fc4166cbe73b1c2e57bc30b to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class Numbers {
public:
// function with int parameter
void num(int x){
cout << "Value of x is: "<< x << endl;
}
// same function with double parameter
void num(double x){
cout << "Value of x is: "<< x << endl;
}
// same function with 2 int parameter
void num(int x, int y){
cout << "Value of x and y is: "<< x << ", " << y << endl;
}
};
int main(){
Numbers value;
// Here the polymorphism will work
// Which function is called will depend on the parameters passed
// Now we will call the first function
value.num(1);
// Now the second function
value.num(2.202);
// Now the third one
value.num(3, 4);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment