Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!hplabs!hpda!hpcupt1!jamiller From: jamiller@hpcupt1.cup.hp.com (Jim Miller) Newsgroups: comp.std.c++ Subject: Re: Multiple inheritance and pointers to base class. Message-ID: <52390006@hpcupt1.cup.hp.com> Date: 4 Dec 90 22:44:47 GMT References: Organization: Hewlett Packard, Cupertino Lines: 54 >Ari Juhani Huttunen > >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 >{}; > . . . Maybe I'm missing your point, but the base class should not contain all the things that the derived classes need. The way you are using Animal, a base class "Object" would need to have all the fields and methods that any program would ever need (say, such a class should be part of the C++ language definition, and so all that coders would need to do is decide what not to use ... :-). An AnimalWithWingsAndTeeth should inherit Animal and add Wings and Teeth, not get rid of run. Please re-post with a good example of the use of what you are talking about, your example seems an example of bad OO design, not of a difficulty in a language. This was not ment as a flame. jim miller jamiller@hpmpeb7.cup.hp.com (a.k.a James A. Miller; Jim the JAM; stupid; @!?$$!; ... ) Anything I say will be used against me ... But my company doesn't know or approve or condone anything of mine here.