I've implemented the field of rational numbers and the operators (+,*,-,/) and (==,>,<) on this field in C++. This was straightforward, I created a class called rational for this.
I've also added the mathematical operators (+,*,-,/) and (==,>,<) for operations between fractions and integers. In my code any operation between an integer and a rational results in a rational.
I'm having trouble with the final step: I want to create an alternative division operator | on the integers, so that int a | int b = rational (a,b). How can this be done in C++? The issue is that I don't know how to add any methods to the "class of integers", I don't know how this "hidden" class can be edited. If I could do this I would just add the method
rational operator | (int x){
rational temp;
temp.numerator=value;
temp.denominator=x.value;
temp.reduce();
return temp;
}
to the integer class. Where I called the class variable of the integer class value. And used my existing reduction method from the rational class.