Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Pointers and Multiple Inheritance Message-ID: <54056@microsoft.UUCP> Date: 12 Apr 90 17:44:29 GMT References: <6170015@hpindda.HP.COM> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 35 In article <6170015@hpindda.HP.COM> daver@hpindda.HP.COM (Dave Richards) writes: >This is probably a trivial question, but I've been hunting through my >documentation and can't find it... Neither could I, when I went looking for it.... >Given a pointer to an instance of a single-inherited subclass, it is >legal to cast that pointer to any of the instance's superclasses. Yes, this is true. >However given an instance of a multiply-inherited class is it legal to cast that pointer to any of the inherited superclasses? I would say not. Wrong guess, this is legal too, if I correctly understand your question. Given class FOOBAR multiply inheriting from FOO and BAR, a FOOBAR* can be cast, either explicetly or implicetly, to either a FOO* or a BAR* C++ compilers are smart enough to correctly do the pointer offsets. Pointer coercions in C++ are not longer necessarily conceptual, but can actually change the bit representations of the pointers involved. But this was always [potentially, at least] true of C implementations too. --If your derivations are private, you can still do all these pointer coercions, but the pointer coercions must be explicet, not implicet. >What then, can a pointer to a multiply-inherited class be cast to? Implicetly, to any of its superclasses. Explicetly, to almost anything. The only restriction I can think of is in some instances of virtual base classes. These are the situations where the virtual base class is handled via delegation. Note: Just 'cuz its "legal" to do these things doesn't necessarily mean its "good" to so.