home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16467 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.8 KB  |  44 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!agate!doc.ic.ac.uk!mrccrc!warwick!bham!bhamvx!mccauleyba
  3. From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
  4. Subject: Re: HELP:  Trouble redefining <<
  5. Sender: usenet@rs6000.bham.ac.uk (USENET News Service)
  6. Message-ID: <1992Nov17.210733.1@vax1.bham.ac.uk>
  7. Date: Tue, 17 Nov 1992 21:07:33 GMT
  8. Lines: 32
  9. References: <1992Nov17.162531.23815@cc.gatech.edu>
  10. Organization: University of Birmingham
  11.  
  12. In article <1992Nov17.162531.23815@cc.gatech.edu>, brianm@cc.gatech.edu (Brian N. Miller) writes:
  13. > Hello, i'm working on a C++ PostScript generator.
  14. > I want to redefine the << operator for a class derived from ostream such that
  15. > it appends a ' ' after outputting any int.
  16. > BROKEN CODE   (Help me fix it...)
  17. > -----------------------------------------
  18. > class ps : private ostream {};
  19. > ps &operator<< (ps &x, int i) { return (ps&) (ps ostream::<< i << ' '); }
  20. > -----------------------------------------
  21. Write out your calls to ostream::operator<< in full to make your code
  22. parseable
  23.  
  24. ps& operator<<(ps& x, int i) {
  25.  return ps.ostream::operator<<(i)<<' ';
  26. }
  27.  
  28. BUT it still won't (I think but I'm not sure) work as a non-member
  29. operator<<(ps&,int) won't hide ostream::operator<<(int) and a
  30. member ps::operator<<(int) would hile all ostream::operator<<()
  31.  
  32. If I'm right and it doesn't work then see my contribution to "Re: What's so
  33. good about streams" (or some subject like that) for a work-round.
  34. -- 
  35.     \\   ( )    No Bullshit!     |  Email: B.A.McCauley@bham.ac.uk   
  36.  .  _\\__[oo        from         |  Voice: +44 21 471 3789 (home)
  37. .__/  \\ /\@    /~)  /~[   /\/[  |    Fax: +44 21 625 2175 (work)
  38. .  l___\\      /~~) /~~[  /   [  |  Snail: 197 Harborne Lane,
  39.  # ll  l\\    ~~~~ ~   ~ ~    ~  |         Birmingham, B29 6SS, UK
  40. ###LL  LL\\   (Brian McCauley)   |   ICBM: 52.5N 1.9W
  41.