Path: utzoo!utgpu!watserv1!watmath!att!dptg!pegasus!hansen From: hansen@pegasus.ATT.COM (Tony L. Hansen) Newsgroups: comp.lang.c++ Subject: Re: How to use Inheritance instead of nesting classes Summary: use multiple inheritance with a pair of intermediate classes Keywords: Inheritance, class Message-ID: <4916@pegasus.ATT.COM> Date: 22 Jul 90 19:24:03 GMT References: <13647@shlump.nac.dec.com> Reply-To: hansen@pegasus.ATT.COM (Tony L. Hansen) Organization: AT&T Bell Labs NJ USA Lines: 39 < 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? The method which occurred to me several years ago when someone else asked me the same question was to use multiple inheritance after introducing a pair of intermediate classes which are used to differentiate between the two lists. Something like this should do the trick: class mouse_button_link : public slink { ... }; class mouse_button_queue : public slist { ... }; class mouse_motion_link : public slink { ... }; class mouse_motion_queue : public slist { ... }; class viewport : public mouse_botton_link, public mouse_motion_link { ... }; Of course, this requires suitable definitions of slink and slist. Tony Hansen att!pegasus!hansen, attmail!tony hansen@pegasus.att.com