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