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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!europa.asd.contel.com!emory!sol.ctr.columbia.edu!usc!cs.utexas.edu!torn!nott!bnrgate!bcrka451!bcrki65!sjm
  3. From: sjm@bcrki65.bnr.ca (Stuart MacMartin)
  4. Subject: Re: Just what is so great about streams?
  5. Message-ID: <1992Nov23.143256.13145@bcrka451.bnr.ca>
  6. Sender: 5E00 Corkstown News Server
  7. Organization: Bell-Northern Research Ltd., Ottawa, Canada
  8. References: <6994@taurus.cs.nps.navy.mil> <1992Nov18.134551.5782@bcrka451.bnr.ca> <7011@taurus.cs.nps.navy.mil>
  9. Date: Mon, 23 Nov 1992 14:32:56 GMT
  10. Lines: 36
  11.  
  12. In article <7011@taurus.cs.nps.navy.mil> skip@taygeta.oc.nps.navy.mil (Skip Carter) writes:
  13. >In article <1992Nov18.134551.5782@bcrka451.bnr.ca>, sjm@bcrki65.bnr.ca (Stuart MacMartin) writes:
  14. >|> 
  15. >|> What about     fout << t << t << endl;   
  16. >|> The wrong operator<<() will be called for the second output unless you provide
  17. >|> the appropriate friend function for TimeStamp, no?
  18. >|> 
  19. >
  20. >    There is no problem at all with      fout << t1<< t2 << endl;
  21. >    Since  the evaluation order is:
  22. >    first,
  23. >        fout << t1;    
  24. >
  25. >    which returns a reference to fout which  is then used in the operation,
  26.  
  27. I think my example was faulty.
  28.                 fout << "The first is " << t1 << " and the second is " << t2 << endl;
  29.  
  30. If operator<<() is overloaded and a friend function is provided for char * but not
  31. for TimeStamp, then (fout << "The first is") returns a reference to fout as a Message,
  32. but (... << t1) returns a reference to fout as an ostream.  Thus the operator<< used
  33. for " and the second is " is the ostream& one, not the Message& one.
  34.  
  35. As has been stated many times, everything is ok so long as you don't try to overload
  36. operator<<.  Otherwise, a friend function has to be defined for every class that
  37. might be output.
  38.  
  39. A few people have claimed in private messages to me that although operator<< is
  40. not virtual, the things it uses are virtual, so I ought to be able to define a
  41. class to do what I want to do without overloading operator<<.  I hope they're right.
  42.  
  43. Stuart
  44. --
  45. : Stuart MacMartin                                    email: sjm@bnr.ca      :
  46. : Bell-Northern Research                              phone: (613) 763-5625  :
  47. : PO Box 3511, Stn C, Ottawa, K1Y-4H7, CANADA    Standard disclaimers apply. :
  48.