Overview
Chapter 13 covers two important concepts in object-oriented programming: operator
overloading and templates. Students will explore how to overload the standard operators
in user-defined classes. They will also learn about the use of the this pointer and
friend functions in user-defined classes. Finally, students will examine how to create
class and function templates in order to provide generic code in a program.
Objectives
In this chapter, the student will:
• Learn about overloading
• Become familiar with the restrictions on operator overloading
• Examine the pointer this
• Learn about friend functions
• Learn how to overload operators as members and nonmembers of a class
• Discover how to overload various operators
• Become familiar with the requirements for classes with pointer member variables
• Learn about templates
• Explore how to construct function templates and class templates
• Become aware of C++11 random number generators
Teaching Tips
Introduction
1. Introduce the concept of writing generic code for related functions and classes, and put
this into the context of object-oriented development.
Why Operator Overloading Is Needed
2. Review the definition of operator overloading.