Let’s say you wanted to write a function to calculate the maximum of two numbers. You might do so like this:
int max(int x, int y)
{
return (x < y) ? y : x;
// Note: we use < instead of > because std::max uses <
}
While the caller can pass different values into the function, the type of the parameters is fixed, so the caller can only pass in int values. That means this function really only works well for integers (and types that can be promoted to int).
So what happens later when you want to find the max of two double values? Because C++ requires us to specify the type of all function parameters, the solution is to create a new overloaded version of max with parameters of type double:
double max(double x, double y)
{
return (x < y) ? y: x;
}
Note that the code for the implementation of the double version of
