home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!agate!doc.ic.ac.uk!mrccrc!warwick!bham!bhamvx!mccauleyba
- From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
- Subject: Re: HELP: Trouble redefining <<
- Sender: usenet@rs6000.bham.ac.uk (USENET News Service)
- Message-ID: <1992Nov17.210733.1@vax1.bham.ac.uk>
- Date: Tue, 17 Nov 1992 21:07:33 GMT
- Lines: 32
- References: <1992Nov17.162531.23815@cc.gatech.edu>
- Organization: University of Birmingham
-
- In article <1992Nov17.162531.23815@cc.gatech.edu>, brianm@cc.gatech.edu (Brian N. Miller) writes:
- > Hello, i'm working on a C++ PostScript generator.
- >
- > I want to redefine the << operator for a class derived from ostream such that
- > it appends a ' ' after outputting any int.
- >
- > BROKEN CODE (Help me fix it...)
- > -----------------------------------------
- > class ps : private ostream {};
- >
- > ps &operator<< (ps &x, int i) { return (ps&) (ps ostream::<< i << ' '); }
- > -----------------------------------------
- Write out your calls to ostream::operator<< in full to make your code
- parseable
-
- ps& operator<<(ps& x, int i) {
- return ps.ostream::operator<<(i)<<' ';
- }
-
- BUT it still won't (I think but I'm not sure) work as a non-member
- operator<<(ps&,int) won't hide ostream::operator<<(int) and a
- member ps::operator<<(int) would hile all ostream::operator<<()
-
- If I'm right and it doesn't work then see my contribution to "Re: What's so
- good about streams" (or some subject like that) for a work-round.
- --
- \\ ( ) 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
-