home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!pipex!warwick!bham!bhamvx!mccauleyba
- From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
- Subject: Re: Just what is so great about streams?
- Sender: usenet@rs6000.bham.ac.uk (USENET News Service)
- Message-ID: <1992Nov19.131702.1@vax1.bham.ac.uk>
- Date: Thu, 19 Nov 1992 13:17:02 GMT
- Lines: 38
- References: <6994@taurus.cs.nps.navy.mil> <1992Nov18.134551.5782@bcrka451.bnr.ca> <1992Nov18.182420.1@vax1.bham.ac.uk> <1992Nov18.205139.12711@bcrka451.bnr.ca>
- Organization: University of Birmingham
-
- In article <1992Nov18.205139.12711@bcrka451.bnr.ca>, sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
- > In article <1992Nov18.182420.1@vax1.bham.ac.uk> mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
- ...
- >>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.
-
- Yes this is true. This is why classes derived from a stream class should
- _not_ redifine operator<<. Different stream classes differ only in their
- IO end not their data formatting end.
-
- For a way to work round this problem don't
- derive your class form a stream class but give it an ostream& member
- and pass though all define:
-
- template <class T> inline
- PseudoStream& operator<<(PseudoStream& ps, const T& data) {
- ps.RealStream << data;
- }
-
- Now you can define PseudoStream::operator<<(const SpecificType&)
-
- Note PseudoStream objects can only be used in << statements not in the
- other ways that streams can be used.
- --
- \\ ( ) No Bullshit! | Email: B.A.McCauley@bham.ac.uk
- . _\\__[oo from | Voice: +44 21 471 3789 (home)
- .__/ \\ /\@ /~) /~[ /\/[ | Fax: +44 21 625 2175 (work)
- . l___\\ /~~) /~~[ / [ | Snail: 197 Harborne Lane,
- # ll l\\ ~~~~ ~ ~ ~ ~ | Birmingham, B29 6SS, UK
- ###LL LL\\ (Brian McCauley) | ICBM: 52.5N 1.9W
-