(Disclaimer Note)
I thank you very much for taking the time to go through this. Please accept my apologies for the long post. English is not my first language and I wanted to be as clear as possible for the review.
(End of Disclaimer)
Hello there. For some context, I bought a book called "The Programmer Idea Book", so that I can practice and better my C++ skills with the projects it brings. One such a project is making a Fraction Class which I have written. The Class can add, subtract, multiply and divide. Simplification needs to be implemented and I may do that later.
At first I had all the code in a single file, but after writing the whole thing I decided to move Fraction to its own class instead (For organizational purposes).
A few points that I considered when writing this class.
-Initially I was considering implementing operator overload for the math, but when I was researching on the subject I found this.
https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading/4421708#4421708
My take away from that article and some other youtube videos is that although Operator Overloads are useful and have their place, one should try to avoid them as much as possible. However when I was coding the class I also consulted "The C++ Programming Language 4th Edition" by Bjarne Stroustrup, in there he goes with the Complex Number example and explains the reasoning behind Operator Overload which actually made sense and was applicable for my Fraction Class as well. Yet, I still have my doubts as to why should I or shouldn't I use overload and when.
For the most part you can ignore main.cpp as it is still in progress, I want to implement an input function for menu selection as well as for entering the fractions when performing operations. The Focus has to be mostly in Fraction.h and Fraction.cpp
Another point I would like you to consider is that overloads of +=, -=, *= and /= are class members while +, -, * and / are helpers that I wrote outside the class in the header files. My initial approach was to put all the overloads as class members, but according to the book this is not necessary as the first set of overload will modify the class itself, while the second set will not. (To be honest I am still trying to get my head around it.) I tried to put the helper functions in Fraction.cpp, but I could not find a way to call them from main, upon some research I was made aware that helper functions are better off outside the class, but on the header file and while this makes sense I don't understand why that is. A final clarification I would like to get is the use of inline. After writing my helper functions in the header file and outside the class, I got an error saying that operator+ was already defined somewhere else in the code, but I couldn't find where, so I wrote the functions as inline and then it worked. The specific question here is, what would cause the compiler to give me that already defined error and why does inline fixes the problem?
If you have any suggestions or comments for the code, I would love to hear them. I am always looking for feedback on how to better my coding skills.
To keep this as short as possible I am posting a link to the github project.
https://github.com/alienguard140/IdeasBookPractice/tree/master/FractionOperations/FractionOperations