Having looked at how to create a class representing a three-dimensional vector in the previous article, we’re going to look at how to add more operator-related functionality to it. We’ll start off with multiplying and dividing by a scalar, and move on to providing non-member operator overloads.
Continue reading “Operator Overloading in Modern C++ (2)”Tag: Math
Operator Overloading in Modern C++ (1)
OO (or OOP) has been used to mean “Object-Oriented (Programming)” for several decades, but there is another use of the acronym OO which is: “Operator Overloading”. Simply put this involves creating (concrete) classes (or types) for which some (or rarely, most, or even all) C++ operators are redefined in terms of functionality related to the class. Since its appearance in the early 1990s, the operator keyword in C++ has been used in numerous applications to allow built-in operators such as +, -= and even -> to be overloaded on a per-class basis. This mini-series intends to demonstrate syntax, techniques, and modern best practices for OO in C++; in this article we’ll start to create a class representing a three-dimensional vector and give it state and functionality.