Path: utzoo!attcan!uunet!samsung!munnari.oz.au!brolga!uqcspe!batserver.cs.uq.oz.au!iain From: iain@batserver.cs.uq.oz.au (Iain Fogg) Newsgroups: comp.lang.c++ Subject: Multiple inheritance and type casting Message-ID: <5087@uqcspe.cs.uq.oz.au> Date: 3 Oct 90 02:02:12 GMT Sender: news@uqcspe.cs.uq.oz.au Reply-To: iain@batserver.cs.uq.oz.au Lines: 68 Assume the following class definitions: class B { . . . public: virtual f ( B &b ); . . . } class D1 : virtual public B { . . . public: virtual f ( B &b ); . . . } class D2 : virtual public B { . . . public: virtual f ( B &b ); . . . } class X : public D1, public D2 { . . . public: virtual f ( B &b ); . . . } If D1::f() cast the formal parameter to type D1 (ie. (D1 &) b), for example to interrogate private data members, no problems. However, if X::f() casts to an X& my compiler complains (TC++ V1.0) saying "Cannot cast from B& to X&". I *know* that when X::f() is called, the actual parameter is an X&. Why is it so? Is there a fix? Email replies and I will summarise. +----------------------------------------------------------------------+ + Dr Iain Fogg + + Senior Research Officer + + + + Department of Computer Science Telephone: (07) 377 2903 + + University of Queensland Fax: (07) 371 0783 + + Queensland Telex: AA40315 + + Australia 4072 email: iain@batserver.cs.uq.oz.au + +----------------------------------------------------------------------+