Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Inheritance & type conversion Message-ID: <761@taumet.com> Date: 7 Jun 91 15:58:38 GMT References: <2348@taurus.cs.nps.navy.mil> Organization: Taumetric Corporation, San Diego Lines: 30 skip@taygeta.oc.nps.navy.mil (Skip Carter) writes: >There are two classes, Base and Derived. >Derived is derived from the Base class and has a method to do a > type conversion from Derived TO Base. >Base has friends functions, report1 and report2. Report1 takes a > reference to a Base, report2 takes the value of a Base, > as the parameter. [ sometimes the user conversion from Derived to Base is called for only one function, sometimes only for the other, depending on compiler. ] The problem is that the language specification defines how a derived class is converted to a base class and under certain circumstances must result in a slice of the same object. That is, under some circumstances the conversion must NOT call a user conversion function. Some cases are (at the moment) undefined as to whether a user conversion will be called. This leaves room for different results from different implementations. Therefore, it is bad practice to declare a user conversion from a derived to a base class, since it sometimes will not be called. -- Steve Clamage, TauMetric Corp, steve@taumet.com