< previous page page_207 next page >

Page 207
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
Operator Overloading
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.

 
< previous page page_207 next page >

If you like this book, buy it!