But actually, that's what the default operator= will do anyways, so you probably don't need to define one yourself (unless you have pointer data members, or this is part of a homework assignment and you're required to define one).
My Rational Temp(inputObj); code here is creating a temporary object, then copying the inputObj using a copy constructor.
Do I still need to individually define each "this" variable as you suggest long double main?
The reason I'm asked my original question is because Visual Studio is giving me the following warning: (*Not saying that after I've made the suggested changes to my function, it tells me this)
"returning address of local variable or temporary"
@ak16
I'm not sure I follow 100% of what your saying. It sounds like to me you are giving an explanation of why it is important to return this, instead of using a temporary variable. If this is the case, then thanks. Otherwise you may need to clarify your meaning.
This is what your assignment operator does right now:
1) Prints a line saying you're inside the = operator
2) Makes a copy of the right-hand side object (i.e. if you did A = B, then it makes a copy of B). Note that this copy is separate from this object and has nothing to do with it.
3) Calls simplifyInt on this copy (presumably, it should already be simplified?)
4) Prints the numerator, denominator, and equation of the copy
5) Returns a reference to the copy. Note that the copy is destroyed at the end of the function, so if you ever try to access it again, all sorts of crazy things could start happening.
Nowhere do you ever actually change the this object.
So if you write A = B; (where A and B are Rational objects), A will never actually change.
Thanks for the clarification! Changes have been made, and some problems solved.
I have another question if I may. Is there a way to refer to the whole object rather than its pieces of the function that is calling the operator?
A = B; A is calling the equals operator with B as the input. Is there a way inside the operator to refer to A as a whole, rather than as, numerator, denominator, equation.?