help with class and constructors
i am a real new with c++, so bare with me here. i have this assignment that asks for a rational number class that overloads the +,-,/,*. I pretty much know how i am going to do it, but there is some specs i don't understand.
the problem says to use a constructor to make sure the denoninator is never zero. now i thought that a constructor was only called as the object was being created, not as it everytime it is used. i am not sure how do do this. i have only used constructors for initializations before now....
for example...
Code:
class RationalNumber {
public:
RationalNumber(int 0, int 1); // this would justt be a default initialization to 0/1
RationalNumber(); // this one would need to be called every time i need to check to see if the denominator is zero?????
};
RatoinalNumber::RationalNumber( int num, int den)
{
num = 0;
den = 1;
}
RationalNUmber::RationalNumber()
{
//do some checking
//do what ever needs to be done
}
i don't really get it. am i misuderstanding the constructor?