TITLE: Auto type conversion selects surprising constructor PROBLEM: James M. Coggins (coggins@cs.unc.edu) I have some classes that need to work together closely so I created constructors for each of them that take an object of each of the other classes. We started seeing some very strange behavior during test runs that we could not explain from our code. It turned out that C++ was doing automatic type conversions using a different path through our class relationships than I wanted. Simplified particulars are as follows: Class Base { Base (Base&) Base (Other&) } class Derived1: public Base { Derived1 (Derived1&) Derived1 (Derived2&) Derived1 (Other&) } class Derived2: public Base { Derived2 (Derived1&) Derived2 (Derived2&) Derived2 (Other&) } Class Other { Other (Derived1&) Other (Derived2&) Other (Other&) } Now when I implemented constructors Derived1::Derived1(Derived2&) and Derived2::Derived2(Derived1&) I referred most of the initialization processing to the base class as in Derived1::Derived1(Derived2& d) : (d) figuring that since d was in fact a kind of Base object that the Base::Base(Base&) constructor would be selected. No such luck. My object d was converted to class Other so that it matched the Base::Base(Other&) constructor. Since Other had different properties from the Derived classes (that's why Other is a different class!) this did not work as expected, leading to some interesting hours of debugging. [ Note that it is generally not a good idea to pollute a class with knowledge of descendent classes, violating principles of encapsulation. - adc ]