Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Newsgroups: comp.lang.c++ Subject: Derived* -> Base* conversion under public/private MI Message-ID: <64530@brunix.UUCP> Date: 11 Feb 91 22:46:40 GMT Sender: news@brunix.UUCP Reply-To: sdm@cs.brown.edu (Scott Meyers) Organization: Brown University Department of Computer Science Lines: 46 If a derived class inherits from a base class both publicly and privately, should there be implicit conversions from a derived pointer to a base pointer? Example: class Base {}; class Derived1: public virtual Base {}; class Derived2: public virtual Base, private Derived1{}; main() { Base *pb = new Derived2; // legal? } The assignment calls for an implicit conversion of a Derived2* to a Base*. AT&T 2.0 says no can do, as does Sun 2.1beta. As usual, g++ has to be different, so it says all is well. The ARM says (p. 36) A pointer to a class may be converted to a pointer to an accessible base class of that class provided the conversion is unambiguous; a base class is accessible if its public members are accessible. This doesn't help much. In the above example, Base's public members are accessible through one path, inaccessible through the other. Because Base is a virtual base class, ambiguity is not a problem here. I seem to recall reading somewhere that if a class inherits from another class both publicly and privately, the public path wins, but I can't find that in Lippman, Dewhurst & Stark, or the ARM. An authoritative answer would be *very* helpful. Thanks, Scott ------------------------------------------------------------------------------- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."