Just learn C + + students are always heard about what operator overload, as if very advanced appearance, then Hey Hei.
Now that we have a time class, we're going to overload the subtraction operator so that the computation between the time classes is the same as the numeric subtraction operation.
First, let's start with the simplest:
Time class:
then the function is implemented: (we only post the implementation of the constructor and sum functions here, because the rest is not available)
Finally, we define the Cmytime class in the main function to add:
after the operation is complete we look at the output:
so the play comes, we change the sum of the time class to operator+,
in the main function
coding. Sum (fixing) changed to coding + fixing;
OK, this is the simplest operator overload, and I'll introduce other knowledge of operator overloading in the next article posting.