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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!ukma!wupost!uwm.edu!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjl
  3. From: pjl@cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: HELP: Trouble redefining <<
  5. Message-ID: <BxvtAA.CLr@cs.uiuc.edu>
  6. Sender: news@cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <1992Nov17.162531.23815@cc.gatech.edu>
  9. Distribution: usa
  10. Date: Tue, 17 Nov 1992 22:32:34 GMT
  11. Lines: 24
  12.  
  13. In <1992Nov17.162531.23815@cc.gatech.edu> brianm@cc.gatech.edu (Brian N. Miller) writes:
  14.  
  15. >Hello, i'm working on a C++ PostScript generator.
  16.  
  17. >I want to redefine the << operator for a class derived from ostream such that
  18. >it appends a ' ' after outputting any int.
  19.  
  20. >BROKEN CODE   (Help me fix it...)
  21. >-----------------------------------------
  22. >class ps : private ostream {};
  23.  
  24. >ps &operator<< (ps &x, int i) { return (ps&) (ps ostream::<< i << ' '); }
  25. >-----------------------------------------
  26.  
  27.     ps_stream& operator<<( int i ) {
  28.         return ostream::operator<<( i ) << ' ';
  29.     }
  30.  
  31.     You don't need and ps& argument (just look at the declaration for
  32.     ostream::operator<<().
  33. -- 
  34.     - Paul J. Lucas                University of Illinois    
  35.       AT&T Bell Laboratories        at Urbana-Champaign
  36.       Naperville, IL            pjl@cs.uiuc.edu
  37.