Created
September 8, 2018 17:51
-
-
Save dibakarsutradhar/b1a910f02fc4166cbe73b1c2e57bc30b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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