www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/05/03:00:23

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Two c++-parser problems
Date: 5 Feb 1998 07:49:06 GMT
Organization: Oxford University, England
Lines: 36
Message-ID: <6bbqti$3v0$3@news.ox.ac.uk>
References: <c2b00813 DOT 34d511b2 AT aol DOT com> <#UWw8xdM9GA DOT 174 AT upnetnews04>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Wed, 4 Feb 1998 21:14:58 -0500 in comp.os.msdos.djgpp DeHackEd
<Not DOT given AT out> wrote:

: And the second error occurs because the command >> is the binary shift command
: or the istream receive operator. That one always makes me wonder - isn't cout <<
: "Hello world!"; usually a binary shift of "cout" left a few thousand places
: (because the pointer will probably in the range of 2048+ at least...), but then
: C++ would considder it a re-write of the default commands. Odd but unusual way
: of using the language to your advantage.

As far as I understand this (and I tend to avoid C++ for various
reasons) the iostreams work through operator overloading.  `<<' and
`>>' aren't assignment operators as you imply -- they're normally
simple arithmetic operators (i.e. they return a value, but don't
assign it to anything).  However, the action of these operators on a
class (cout and cin are instances of classes) can be overloaded (as
can many operators' actions), i.e. replaced with a method in the
class.  These methods for iostreams happen to read from input streams
and write to output streams.

There's nothing particularly special about the choice of `<<' and
`>>'; many other (binary) operators would have done, e.g.:

cout + "Hello world!" + endl;
cin * a;

if `+' and `*' had been overloaded instead.

As I said, this is just `AFAIK' and I'm not a great C++ user -- take
it with a pinch of salt, and UTSL if you're really curious (it ought
to be in iostream.h).

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

Remember what happened to the dinosaurs.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019