Functions: Overloading and Default Parameters

Function Overloading

The term function overloading refers to the way C++ allows more than one function in the same scope to share the same name -- as long as they have different parameter lists

Avoiding Ambiguity


Default parameters:

In C++, functions can be made more versatile by allowing default values on parameters. This allows some parameters to be optional for the caller

Default parameters and overloading

A function that uses default parameters can count as a function with different numbers of parameters. Recall the three functions in the overloading example:
   int Process(double num);		  // function 1
   int Process(char letter);              // function 2
   int Process(double num, int position); // function 3
Now suppose we declare the following function:
   int Process(double x, int y = 5);	  // function 4
This function conflicts with function 3, obviously. It ALSO conflicts with function 1. Consider these calls:
   cout << Process(12.3, 10);	// matches functions 3 and 4
   cout << Process(13.5);	// matches functions 1 and 4
So, function 4 cannot exist along with function 1 or function 3

BE CAREFUL to take default parameters into account when using function overloading!