From the course: C++ Essential Training

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Operator overloads

Operator overloads - C++ Tutorial

From the course: C++ Essential Training

Operator overloads

- Operator overloading is the ability to use common operators with user defined objects and classes. It's not unique to C++, in fact it was one of the original concepts borrowed from ALGOL for C++, but how C++ does it is fairly unique and extremely powerful. There are two distinct ways to overload operators in C++: with member functions, as part of a class definition, or as separate non-member functions. In this lesson, we'll talk about the member functions in your class definitions. We'll discuss the operator non-member functions in the next lesson. This is Rational .cpp from chapter seven of the exercise files. This is a fully functional class that performs four function arithmetic on rational numbers as fractions, and the class here is called Rational. We can see it has two data members, a numerator and a denominator, and we can see that has a couple of constructors and a destructor. This first constructor.…

Contents