E define as class members to overload io operators and

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: -> () You cannot overload the following operators (not complete): . :: ?: You cannot overload the symbol # 2/16/2011 10 For output <<, input >> operators << >> However, However, we can NOT use the internal way, (i.e. define as class members) to overload I/O operators << and >> !! >> See See it again: ostream ostream & operator<<(ostream & out, Time & t) Ti t) const { t.display(out); t.display(out); return out; } Define a method display and call it in the definition and of the overloading 2/16/2011 11 void Time::display(ostream & out) const Time::display(ostream { out << myHours << ':' << (myMinutes < 10 ? "0" : "") << myMinutes << ' ' << myAMorPM << ".M. (" << myMilTime << " mil. time)"; } “Overloading <<“ let user can use cout cout << classTime; instead of classTime.display(cout); classTime.display(cout); for output Similar way for overloading input operator >> (text Fig 4.7 ) Question: Question: Can we put the statements in display method inside of the overloading << function directly? ostream & op...
View Full Document

This note was uploaded on 10/21/2011 for the course CMPSC 122 taught by Professor Formitchev during the Spring '08 term at Pennsylvania State University, University Park.

Ask a homework question - tutors are online