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

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…

Contents