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...
i don't really get it. am i misuderstanding the constructor?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 }



LinkBack URL
About LinkBacks



enIsSetAsZeroException (Outerclass::Innerclass)....
"I am new to c++", and you're telling him to throw and catch exceptions already? And throwing classes at that?? Yeesh, might as well tell him to learn Winsock API! (I heard that's difficult to figure out