(upbeat music)
- [Speaker] For this Challenge,
you will implement non-member operators
for the rational class from this chapter.
Here is a working copy of 06 challenge.cpp
from chapter six of the exercise files.
This is another version of the rational class
from earlier in this chapter.
The first thing you'll notice
about this code is that it doesn't compile.
If I try to build, it says build failed.
And if we scroll down here to the bottom
we'll see why it fails.
We have our four arithmetic operations
with integers on the left-hand side
you notice that they compile fine with the integers
on the right hand side, but they're not working
with the integers on the left-hand side.
If I go ahead and comment out these lines
and build and run you'll notice that it works fine.
It'll do the addition and subtraction, multiplication
and division with the integers on the right-hand side
but it will not compile
with the integers on the left-hand side.
As we learned in this chapter
these expressions require non-member operators.
Your task is to modify this class
to use non-member functions for the arithmetic operations
so that these four lines of code compile and run properly.
This challenge should take you about 15 minutes
as always feel free to take your time and experiment
and I'll show you my solution in the next movie.