Friends and Operator Overloading
This chapter will continue our pursuit of expanding your C++ programming repertoire beyond OOP concepts, with the goal of writing more extensible code. We will next explore friend functions, friend classes, and operator overloading in C++. We will understand how operator overloading can extend operators beyond their usage with standard types to behave uniformly with user defined types, and why this is a powerful OOP tool. We will learn how friend functions and classes can be safely used to achieve this goal.
In this chapter, we will cover the following main topics:
- Understanding friend functions and friend classes, appropriate reasons to utilize, and measures to add safety to their usage
- Learning about operator overloading essentials – how and why to overload operators, ensuring operators are polymorphic between standard and user defined types
- Implementing operator functions and knowing when friends may be necessary