Xref: utzoo comp.lang.c++:10636 comp.std.c++:459 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!news.funet.fi!funic!santra!santra!ahuttune From: ahuttune@niksula.hut.fi (Ari Juhani Huttunen) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Multiple inheritance and pointers to base class. Message-ID: Date: 30 Nov 90 22:03:46 GMT Sender: news@santra.uucp (Cnews - USENET news system) Organization: Helsinki University of Technology, Finland Lines: 75 How do you use multiple inheritance and pointers to a base class object at the same time? Suppose you have many different classes from which you wish to construct objects using multiple inheritance and you also wish to access these objects through a pointer to their common base class. Example: Animal - AnimalWithWingsAndTeeth - AnimalWithWingsAndFeet - AnimalWithFeetAndScales ... You access these through a pointer to Animal. You have implemented classes named Wings, Teeth, Feet, Scales that implement functions fly, bite, run, protect. (And NoWings, NoTeeth, NoFeet, NoScales that do not.) The easy way to proceed would be: class Animal { public: virtual fly() = 0; virtual bite() = 0; virtual run() = 0; virtual protect() = 0; }; class AnimalWithWingsAndTeeth : public Wings, public Teeth, public NoFeet, NoScales {}; class AnimalWithWingsAndFeet : public Wings, public NoTeeth, public Feet, NoScales {}; class AnimalWithFeetAndScales : public NoWings, public NoTeeth, public Feet, Scales {}; Instead you are forced to write: class AnimalWithWingsAndTeeth : public Wings, public Teeth, public NoFeet, NoScales { public: fly() { Wings::fly(); } bite() { Teeth::bite(); } run() { NoFeet::run(); } protect() { NoScales::protect(); } }; class AnimalWithWingsAndFeet : public Wings, public NoTeeth, public Feet, NoScales { public: fly() { Wings::fly(); } bite() { NoTeeth::bite(); } run() { Feet::run(); } protect() { NoScales::protect(); } }; class AnimalWithFeetAndScales : public NoWings, public NoTeeth, public Feet, Scales { public: fly() { NoWings::fly(); } bite() { NoTeeth::bite(); } run() { Feet::run(); } protect() { Scales::protect(); } }; My question: Is it really necessary to force a programmer to write this much (and more since this is only a small example) unnecessary code? Why can't the multiple inheritance of a non-virtual function, say Wings::fly(), re-define a virtual function Animal::fly() ? Am I missing something? -- ___ ___ ___ ___ ___ ___ ___ ___ ___ __I I__I I__I I__I I__I I__I I__I I__I I__I I Bird of Night: 2 cl Kahlua Ari Huttunen (ahuttune@niksula.hut.fi) I 2 cl Jameson ____________________________________________I add ice cubes Brought to you by Super Global Mega Corp .com