Argument Type Differences

Overloaded functions differentiate between argument types that take different initializers. Therefore, arguments of a given type, and a reference to that type are considered the same for the purposes of overloading. They are considered the same because they take the same initializers. For example, max( double, double ) is considered the same as max( double &, double & ). It is an error for overloaded functions to differ only in this manner.

For the same reason, function arguments of a type modified by const or volatile are not treated differently than the base type for the purposes of overloading.

However, the function overloading mechanism can distinguish between references that are qualified by const and volatile, and references to the base type. This makes code such as the following possible:

#include <iostream.h>

class Over

{

public:

Over() { cout << “Over default constructor\n”; }

Over( Over &o ) { cout << “Over&\n”; }

Over( const Over &co ) { cout << “const Over&\n”; }

Over( volatile Over &vo ) { cout << “volatile Over&\n”; }

};

main()

{

Over o1; // Calls default constructor.

Over o2( o1 ); // Calls Over( Over& ).

const Over o3; // Calls default constructor.

Over o4( o3 ); // Calls Over( const Over& ).

volatile Over o5; // Calls default constructor.

Over o6( o5 ); // Calls Over( volatile Over& ).

return 0;

}

Pointers to const and volatile objects are also considered different from pointers to the base type for the purposes of overloading.