|
|
|
|
|
|
|
Hour 14
Operator Overloading |
|
|
|
|
|
|
|
|
In the previous hour you learned how to overload member methods and how to create a copy constructor to provide deep copies. In this hour you will learn. |
|
|
|
|
|
|
|
|
How to overload member functions |
|
|
|
|
|
|
|
|
How to overload the assignment operator to manage memory |
|
|
|
|
|
|
|
|
How to write functions to support classes with dynamically allocated variables |
|
|
|
|
|
|
|
|
C++ has a number of built-in types, including int, real, char, and so forth. Each of these has a number of built-in operators, such as addition (+) and multiplication (*). C++ enables you to add these operators to your own classes as well. |
|
|
|
|
|
|
|
|
In order to explore operator overloading fully, Listing 14.1 creates a new class, Counter. A Counter object will be used in counting (surprise!) in loops and other applications where a number must be incremented, decremented, or otherwise tracked. |
|
|
|
|
|