Let us suppose we wish to create a function
myFunc() that can take in three integers as arguments -
int x, int y, int z and returns
(x*y)+z. It is fairly easy to write such a function. But what if later on we wish to give the same sort of functionality for three arguments of type - double, lets say -
double a, double b, double c. Can this be achieved without creating a function with a new name?
Lets have a look at the code given below -
Note that the compiler automatically detects which *version* of the method to use when you call
myFunc() depending upon the
type of arguments.
| Advertisement |

No comments:
Post a Comment