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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!pipex!warwick!bham!bhamvx!mccauleyba
  3. From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
  4. Subject: Re: Just what is so great about streams?
  5. Sender: usenet@rs6000.bham.ac.uk (USENET News Service)
  6. Message-ID: <1992Nov18.182420.1@vax1.bham.ac.uk>
  7. Date: Wed, 18 Nov 1992 18:24:20 GMT
  8. Lines: 40
  9. References: <1992Nov12.061942.16473@nuscc.nus.sg> <TMB.92Nov13102951@arolla.idiap.ch> <6994@taurus.cs.nps.navy.mil> <1992Nov18.134551.5782@bcrka451.bnr.ca>
  10. Organization: University of Birmingham
  11.  
  12. In article <1992Nov18.134551.5782@bcrka451.bnr.ca>, sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
  13. > In article <6994@taurus.cs.nps.navy.mil> skip@taygeta.oc.nps.navy.mil (Skip Carter) writes:
  14. >>    Now the TimeStamp class can write a comment WITH NO CHANGES MADE TO
  15. >>    THE TIMESTAMP CLASS.
  16.     ...
  17. >>    In fact, TimeStamp can properly write to any class that is ultimately
  18. >>      derived from ostream.
  19. >>
  20. > What about     fout << t << t << endl;   
  21. > The wrong operator<<() will be called for the second output unless you provide
  22. > the appropriate friend function for TimeStamp, no?
  23. No.
  24.  
  25. What wrong operator<<()? There only is one that can possibly be called:
  26.   ostream& operator<< (ostream&,const TimeStamp&)
  27.  
  28. Are you thinking that << associates right?
  29.  
  30. fout << t << t << endl;
  31.   is not...
  32. operator<<(fout,operator<<(t,operator<<(t,endl)))                             
  33.  
  34.   it is..
  35. operator<<(operator<<(operator<<(fout,t),t),endl)                             
  36.                       \-----v---------/
  37.                   Returns a ref to `fout'
  38.            \---------------v--------------/
  39.                 Returns a ref to `fout'
  40.  
  41. the inner to calls to operator<< call the same operator.
  42. OK so an ostream& is used to refer to `fout' but when we get down to
  43. the nitty-gritty of stream io everything is virtual so this doesn't matter.
  44. -- 
  45.     \\   ( )    No Bullshit!     |  Email: B.A.McCauley@bham.ac.uk   
  46.  .  _\\__[oo        from         |  Voice: +44 21 471 3789 (home)
  47. .__/  \\ /\@    /~)  /~[   /\/[  |    Fax: +44 21 625 2175 (work)
  48. .  l___\\      /~~) /~~[  /   [  |  Snail: 197 Harborne Lane,
  49.  # ll  l\\    ~~~~ ~   ~ ~    ~  |         Birmingham, B29 6SS, UK
  50. ###LL  LL\\   (Brian McCauley)   |   ICBM: 52.5N 1.9W
  51.