Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!ncifcrf!lhc!nih-csl!sparkler.dcrt.nih.gov!kgorlen From: kgorlen@sparkler.dcrt.nih.gov (Keith Gorlen) Newsgroups: comp.lang.c++ Subject: Re: How to use Inheritance instead of nesting classes Summary: See Chapter 13 of "Data Abstraction and O-OP in C++" Keywords: Inheritance, class Message-ID: <231@nih-csl.nih.gov> Date: 21 Jul 90 03:24:47 GMT References: <13647@shlump.nac.dec.com> Sender: news@nih-csl.nih.gov Organization: National Institutes of Health, Bethesda, MD Lines: 37 In article <13647@shlump.nac.dec.com> heintzefmcsse.enet.dec.com (Sieg Heintze) writes: >I have some entities, viewports to be specific, that must be able to reside >multiple doubly linked lists at once. In otherwords, a view port might be >both in the "mouse button depress queue" and in the "mouse motion queue" >at the same time. > >For an entity to reside on a single list I could follow Bjarne's example in his >book just fine. But how do I define an object that resides on multiple >lists and use inheritance? Can I inherit the same object twice in the >same class? Chapter 13 of our new book, "Data Abstraction and Object-Oriented Programming in C++", shows how to write a class that uses multiple inheritance to inherit two instances of a base class, Link, so that instances of it can reside on two *singly* linked lists at the same time. You could use the same approach for *doubly* linked lists, I'm sure. Briefly, the trick is that you must derive two classes from class Link, say ButtonQLink and MotionQLink, them multiply derive your class Viewport from these. This is necessary so that you have some way of disambiguating references to the two Link subobjects in a Viewport object. Reference: "Data Abstraction and Object-Oriented Programming in C++" Keith E. Gorlen, Sanford M. Orlow, and Perry S. Plexico John Wiley & Sons ISBN 047192346X $39.25 (paperback) ISBN 047192752X $16.95 (NIH Class Library + examples, 2 disk set) ISBN 0471927511 $82.70 (cloth + 2 disk set) -- Keith Gorlen phone: (301) 496-1111 Building 12A, Room 2033 uucp: uunet!nih-csl!kgorlen National Institutes of Health Internet: kgorlen@alw.nih.gov Bethesda, MD 20892