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 - 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.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Overview of classes and objects5m 43s
-
(Locked)
Data members3m 36s
-
(Locked)
Function members4m 27s
-
(Locked)
Constructors and destructors8m 7s
-
(Locked)
Operator overloads5m 28s
-
(Locked)
Non-member operators5m 31s
-
(Locked)
Challenge: Non-member operators54s
-
(Locked)
Solution: Non-member operators1m 20s
-
(Locked)
-
-
-