By Stephen R. Davis

Since C++ passes the value of the argument, you cannot differentiate by const-ness. In the following, what actually gets passed to maximum() are the values 2.0 and 0.0. The maximum() function can’t tell whether these values came from a variable like dArg or a constant like 0.0.

double maximum(double d1, double d2);
void otherFunction()
{
    double dArg = 2.0;
    double dNonNegative = maximum(dArg, 0.0);

You can declare the arguments of a function to be const. Such a declaration means that you cannot change the argument’s value within the function. This is demonstrated in the following implementation of maximum(double, double):

double maximum(const double d1, const double d2)
{
    double dResult = d1;
    if (d2 > dResult)
    {
        dResult = d2;
    }
    // the following would be illegal
    d1 = 0.0; d2 = 0.0
    return dResult;
}

The assignment to d1 and d2 is not allowed because both have been declared const and therefore are not changeable.

What is not legal is the following:

// these two functions are not different enough to be distinguished
double maximum(double d1, double d2);
double maximum(const double d1, const double d2);
void otherFunction()
{
    double dArg = 2.0;
    // C++ doesn't know which one of the above functions to call
    double dNonNegative = maximum(dArg, 0.0);

Here C++ has no way of differentiating between the two when you make the call.