Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!uw-beaver!rice!kappa.Rice.EDU!rich From: rich@kappa.Rice.EDU (Richard Murphey) Newsgroups: comp.lang.c++ Subject: Re: Use of inheritance for classification? (iostream) Keywords: MI, iostream Message-ID: <3297@kalliope.rice.edu> Date: 19 May 89 19:58:46 GMT References: <11557@ulysses.homer.nj.att.com> <30582@apple.Apple.COM> <10248@riks.csl.sony.JUNET> <329@odi.ODI.COM> <327@calmasd.Prime.COM> Sender: usenet@rice.edu Lines: 72 > Here is an example that I think satisfies the above request. It isn't > contrived, its simple, and its a familiar "problem domain". > > The iostream library that is scheduled to be part of 2.0 uses > > class ios { ... } > > class istream : virtual public ios { ... } ; > > class ostream : virtual public ios { ... } ; > > class iostream : public istream, public ostream { ... } ; > > Input operations are allowed on istreams. Output operations on > ostreams. iostreams allow both operations (as when updating disk > files) > [picture omitted] > > Jerry Schwarz > AT&T Bell Labs, Murray Hill For the novice C++ programmer iostreams seems like one of the most attractive features of C++. Your example works fine with g++-1.35.0! #include #define nl <<"\n" #define sp <<" "<< class iostream : public istream, public ostream { iostream(); }; iostream::iostream() :istream(stdin), ostream(stdout) { } int main(int argc, char *argv[]) { char a[80]; iostream h; h << "test" nl; h >> a; h << "got" sp a nl; return 0; } Script started on Fri May 19 14:56:23 1989 rich@kappa /usr1/rich/pub/135/t> make t g++ -g -Wall t.C -o t -lm rich@kappa /usr1/rich/pub/135/t> t test stuff got stuff rich@kappa /usr1/rich/pub/135/t> exit rich@kappa /usr1/rich/pub/135/t> script done on Fri May 19 14:56:58 1989 I don't claim to understand Multiple inheritance well, but this instance of it does seem useful as you suggest. Regards, Rich Murphey Electrical Engineering Rice University rich@rice.edu