home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!utcsri!skule.ecf!torn!nott!bnrgate!bcrka451!bcrki65!sjm
- From: sjm@bcrki65.bnr.ca (Stuart MacMartin)
- Subject: Re: Just what is so great about streams?
- Message-ID: <1992Nov18.205139.12711@bcrka451.bnr.ca>
- Sender: 5E00 Corkstown News Server
- Organization: Bell-Northern Research Ltd., Ottawa, Canada
- References: <6994@taurus.cs.nps.navy.mil> <1992Nov18.134551.5782@bcrka451.bnr.ca> <1992Nov18.182420.1@vax1.bham.ac.uk>
- Date: Wed, 18 Nov 1992 20:51:39 GMT
- Lines: 48
-
- In article <1992Nov18.182420.1@vax1.bham.ac.uk> mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
- >In article <1992Nov18.134551.5782@bcrka451.bnr.ca>, sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
- >> In article <6994@taurus.cs.nps.navy.mil> skip@taygeta.oc.nps.navy.mil (Skip Carter) writes:
- >>> Now the TimeStamp class can write a comment WITH NO CHANGES MADE TO
- >>> THE TIMESTAMP CLASS.
- > ...
- >>> In fact, TimeStamp can properly write to any class that is ultimately
- >>> derived from ostream.
- >>>
- >>
- >> What about fout << t << t << endl;
- >> The wrong operator<<() will be called for the second output unless you provide
- >> the appropriate friend function for TimeStamp, no?
- >No.
- >
- >What wrong operator<<()? There only is one that can possibly be called:
- > ostream& operator<< (ostream&,const TimeStamp&)
- >
- >Are you thinking that << associates right?
- >
- >fout << t << t << endl;
- > is not...
- >operator<<(fout,operator<<(t,operator<<(t,endl)))
- >
- > it is..
- >operator<<(operator<<(operator<<(fout,t),t),endl)
- > \-----v---------/
- > Returns a ref to `fout'
- > \---------------v--------------/
- > Returns a ref to `fout'
- >
- >the inner to calls to operator<< call the same operator.
- >OK so an ostream& is used to refer to `fout' but when we get down to
- >the nitty-gritty of stream io everything is virtual so this doesn't matter.
-
- Perhaps I was thinking too general. If the class of fout does not need to
- redefine operator<<(), everything is ok. But if there is some processing
- that has to be done before the data is passed to the underlying stream,
- doesn't the class of fout have to redefine operator<<()? In which case
- my example does not work. Because operator<<() is *not* virtual. I don't
- think it is true that TimeStamp can properly write to *any* class that
- is ultimately derived from ostream. And if it can, I'd sure like to know how.
-
- Stuart
- --
- : Stuart MacMartin email: sjm@bnr.ca :
- : Bell-Northern Research phone: (613) 763-5625 :
- : PO Box 3511, Stn C, Ottawa, K1Y-4H7, CANADA Standard disclaimers apply. :
-