Applied programming or the friend equivalent for each

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: cin.get cin.eof and cout.put are just public functions. Applied Programming W e can, however, write a friend function We friend friend ostream& operator<<(ostream&, friend ostream const TimeType&); const TimeType and place this in the declaration of our class and TimeType, before the public or private parts TimeType before public or private parts as in as class TimeType class TimeType { friend ... Here's what the implementation looks like. Applied Programming or the friend equivalent, for each type of or friend equivalent, type of built-in. built But they belong to the class ostream. But ostream Applied Programming ostream& operator<<(ostream& os, const TimeType& time) os const TimeType { // time is output in the form HH:MM:SS if (time.hours < 10) os << '0'; os << time.hours << ':'; << time.hours if (time.minutes < 10) os << '0'; os << time.minutes << ':'; << time.minutes if (time.seconds < 10) os << '0'; os << time.seconds; << time.seconds return os; return os } There is no friend prefix here in the Th...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online