Original Post
Getting this error using VC++ with SP6. What could I be doing wrong? error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class ClockDigit' (or there is no acceptable conversion). Here is the code: #include using namespace std; class ClockDigit { public: ClockDigit(int b, ClockDigit *n = 0):base(b), count(0), nextdigit(n){} void increment(); void Set(int i) { if ((i >= 0) && (i < base)) count = i; } int theCount() const {return count;} private: int count; // increment this periodically const int base; // when (count >= base), reset count to 0 ClockDigit *const nextdigit; }; void ClockDigit::increment() { ++count; if (count >= base) { count = 0; if (nextdigit != 0) nextdigit -> increment(); // carry over } } class Clock { public: Clock():second(60, &minute), minute(60, &hour), hour(24){} void Set(int h, int m, int s) {hour.Set(h); minute.Set(m); second.Set(s);} void increment() {second.increment();} friend ostream& operator<<(ostream &os, const Clock &mc); private: ClockDigit second; ClockDigit minute; ClockDigit hour; }; ostream& operator<<(ostream &os, const Clock &mc) { Clock CL; os << CL.hour << ":" << CL.minute << ":" << CL.second << "\n"; return os; } int main() { Clock CL; CL.Set(23, 59, 50); for (int ii=0; ii < 100; ii++) { cout << CL << "\n"; CL.increment(); } return 0; }