Path: utzoo!attcan!uunet!decwrl!petunia!news From: jdunn@polyslo.CalPoly.EDU (Drunk Dude #3) Newsgroups: comp.lang.c++ Subject: Re: Multiple inheritance and type casting Message-ID: <2709eabf.5abd@petunia.CalPoly.EDU> Date: 3 Oct 90 13:42:23 GMT References: <5087@uqcspe.cs.uq.oz.au> Organization: The Consistently Drunk Dudes of Spike's Lines: 45 In article <5087@uqcspe.cs.uq.oz.au> iain@batserver.cs.uq.oz.au writes: > >Assume the following class definitions: > [...] > >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&". This works for me: void X::f(X &x) {} // standard method def X x; Y y; // Y is derived from X X.f(*(X *)&y); // get a pointer and convert the pointer This actually makes sense, because converting from one object to another requires a new (anonymous) object to be created, and that requires that a constructor exist on the casted-to type to do the conversion. I have found one bug in TC++ 1.0 involving multiple inheritance, and I believe I am in the process of tracking another down now. If you want me to send you a copy of the compiler-breaking code when I send it off to Borland, let me know. Probably be a week before I get around to it, though... >+----------------------------------------------------------------------+ >+ Dr Iain Fogg + >+----------------------------------------------------------------------+ -jd -- Major@Jungle1 Plans to go with the flow have the one flaw of being plans jdunn@polyslo.CalPoly.EDU