Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!bloom-beacon!tut.cis.ohio-state.edu!ucbvax!ulysses!hector!jss From: jss@hector.UUCP (Jerry Schwarz) Newsgroups: comp.lang.c++ Subject: Re: Use of inheritance for classification? Message-ID: <11557@ulysses.homer.nj.att.com> Date: 19 May 89 14:34:47 GMT References: <30582@apple.Apple.COM> <10248@riks.csl.sony.JUNET> <329@odi.ODI.COM> <327@calmasd.Prime.COM> Sender: netnews@ulysses.homer.nj.att.com Reply-To: jss@hector.UUCP (Jerry Schwarz) Organization: AT&T Bell Laboratories Lines: 49 In article <327@calmasd.Prime.COM> wlp@calmasd.Prime.COM (Walter L. Peterson, Jr.) writes: >Part of the problem with multiple inheritance is finding good cases >for its proper use. Most of the examples that I have seen, including >the original posting above, have the common problem of being too >contrived and more appropriately solved by other means. The only >example that I have seen that is both simple and from a familiar >problem domain to be used as a general example is from biological >taxonomy. 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 mulitple inheritance in the following way: class ios { ... } class istream : virtual public ios { ... } ; class ostream : virtual public ios { ... } ; class iostream : public istream, public ostream { ... } ; Or in pictures ios / \ / \ / \ istream ostream \ / \ / \ / iostream Input operations are allowed on istreams. Output operations on ostreams. iostreams allow both operations (as when updating disk files) The abstract model of a stream is a sequence of characters with a pointer. istream, ostream, iostream operate on the same abstraction but allow different operations. This improves compile time type. checking. (E.g. attempts to input from cout are caught at compile time.) Jerry Schwarz AT&T Bell Labs, Murray Hill