In this section of the course, we’ll learn about overloading operators in c++.
C++ allows the programmer to overload most operators to work with user-defined classes.
This is intended to make code more readable and writable
by allowing the use of familiar operators in a familiar manner,
but with our own classes and objects.
First look at exactly what operator overloading is
and some of the basic rules that C++ enforces.
We’ll start with the assignment operator.
The assignment operators a very important operator in C++.
It defines the semantics of what happens when you assigned one object to another.
C++ provides a default way of doing object assignment
much as it did with the copy constructor that we learned about in the last section.
However, many times we want to be in control of what happens during object assignment,
and we can overload the assignment operator to do exactly that.
For example, when we use raw pointers in our classes,
we must provide our own version of the assignment operator.
Additionally, we could override the assignment operator to handle both
copy and move semantics as we did with the copy
and move constructors in the last section.
We will learn how to do that in this section.
We’ll also see how we can overload other operators as both member functions
and its global functions, and why do we want to choose one over the other.
We’ll finish up this section by overloading the stream insertion and extraction operator
so that we can easily use our objects with c++ streams
just like we've been doing with the built-in types.
So let's get started with operator overloading.