back
Overloading Functions
Before we get much further in our study of Object Oriented Programming, we need to cover a super important C++ concept called "Overloading Functions."

To "overload" a function means to define multiple versions of the same function. The way this is accomplished is by using different types.

For example, you could create two functions :

calculate (int x);

calculate (float x);

C++ will be able to distinguish which one you actually want to use depending on the type of data you use with the function.

You can also use two functions with the same name if you vary the number of arguments inside the function:

calculate(float f1):

calculate(float f1, float f2):

This is also acceptable.

The reasons why you want to overload functions may not be obvious at the moment. You will see as you start writing longer and more complex programs (especially when you are using multiple classes) that overloading functions gives you a great deal more control and flexibility with your programming.

Assignment

Ask me for today's handout entitled, "Example of Overloading Functions." Compile and execute the program.