I am trying to overload an the >> operator for my new Money class. It compiles fine, however when it gets to the point where i use the operator it, seems to loop the input method for a while and then end the program skipping any code after it. Any ideas?
Code:money.h class Money { private: int cents; public: Money(); Money(int cent); void input(istream &in) const; }; istream & operator>> (istream & in, const Money & m);Code:money.cpp Money::Money(){} Money::Money(int cent) { cents = cent; } void Money::input(istream &in) const { //THIS IS WHERE IT LOOPS UNTIL ENDING THE PROGRAM in >> cents; } istream& operator>>(istream & in, const Money &m) { m.input( in ); return in; }The program never allows you to enter anything from the cin >> cents command. I have more code, but i am trying to simplify it...if you need to see more, let me know.Code:testMoney.cpp int main() { Money m(); cin >> m; }
Thanks



LinkBack URL
About LinkBacks



. sorry codeplug for not being more thorough, and the m() was a typo, so everything compiles and runs as desired