From the course: C Essential Training
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Solution: Non-member operators - C Tutorial
From the course: C Essential Training
Solution: Non-member operators
(upbeat music) - [Instructor] The challenge for this chapter was to implement non-member operators for the rational number class. Here's my solution. This is 07 Solution from Chapter 7 of the exercise files. And if we come down here, you'll notice that we no longer have the operator overloads as part of the class. We still have the assignment operator, but we no longer have the arithmetic operators. And down here in the implementation, you see that we have the operator overloads as non-member functions with both left-hand side and right-hand side rational parameters. And you notice that we're using the getters now. Left-hand side numerator, right-hand side denominator functions, and those are the member functions up here in the class that return the numerator and denominator values. And down here in Maine, we see that all of this compiles. I'll build and run and you can see it works as expected. This challenge…
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)
-
-
-