Operator overloading in C++
Operators are a fundamental part of programming languages. They allow us to perform operations on operands
by using a symbol. If you have ever written code, you probably know what this snippet does:
1
int a = 3 + 1;
Variable a
will be initialized to 4. It is initialized to this value, because the +
operator has been used to add the values of 3 and 1. The =
sign, is also an operator that assigns the value of the addition to the variable a
.
We use these operators without thinking too much about them, but they are just symbols that perform a certain action, like any function we could define.
It turns out we can override the behavior of an existing operator. That’s what this article will focus on.