So I am making a rational number class. Ive got it most of the way done accept when I use the + operator the program crashes.
So I have a Rational class. All my operators are in the Rational class. My << and >> are friends of Rational class.
1 2 3 4 5 6 7 8
// Here is my + overloaded operator
Rational Rational::operator+(const Rational &rhs){
Rational temp;
int cmd = denom * rhs.denom;
temp.num = (num*rhs.denom)+(rhs.num+denom);
temp.denom = cmd;
return temp;
}
When I declare Rational objects a, b , c and try say a=b+c the program stops working. Is this operator wrong or could it be a problem with the = operator?
I just don't know. Any help would be awesome. Thanks
I can post more of the code if needed.
Make sure you have implemented the copy constructor Rational(const Rational &); and the copy assignment operator Rational &operator=(const Rational &); correctly.