Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!cs.utexas.edu!uunet!lpi.liant.com!pkt From: pkt@lpi.liant.com (Scott Turner) Newsgroups: comp.lang.c++ Subject: Re: Inheritance & type conversion Summary: murky in ARM Message-ID: <1991Jun19.162619.9705@lpi.liant.com> Date: 19 Jun 91 16:26:19 GMT References: <2348@taurus.cs.nps.navy.mil> <761@taumet.com> <1991Jun14.100558.3061@jyu.fi> Organization: Language Processors Inc., Framingham MA Lines: 72 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. ... > Derived dtype; > > report2( dtype ); > > cases a conversion to Base with Zortech C++, BUT NOT for Turbo C++ sakkinen@jyu.fi (Markku Sakkinen) writes: > [Opinion that Zortech handles both cases right and Turbo wrong.] > Some years ago, Turbo Pascal seemed to be a lot more Turbo than Pascal > on several aspects. Maybe that is the current situation with Turbo C++? Not at all. The C++ part of Turbo C++ was developed outside of Borland by people who did all they could to conform to de facto and documented standards. > >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. > > I don't believe this either. Can you cite the pertinent sections > of the ARM? p. 288 of the ARM says, "The initialization that occurs in argument passing and function return is equivalent to the form T x = a;" p. 284 says, "Alternatively a single value is specified as the initializer using the = operator. This value is used as the argument to a copy constructor." Section 12.3.2 of the ARM describes how a conversion function defines a conversion, but does not specify how the conversion function might override or be used in preference to any other conversion. It does say, "User-defined conversions are used implicitly only if they are unambiguous." Chapter 4 describes the built-in conversion from reference-to-derived to reference-to-base, but does not mandate conversion from derived to base. That's all the ARM says, outside of commentary and examples, none of which directly address our subject. Since the copy constructor takes an argument of type "const T&", p. 284 implies that T x = a; is equivalent to const T & ref = a; T x (ref); This reasoning supports an automatic conversion from derived to base in most cases, and would explain its omission from chapter 4 of the ARM. Note also that it supports Turbo's interpretation of Carter's "report2" example, not Zortech's and cfront's. Disclaimer: The developers of the C++ part of Turbo have consulted for LPI. -- Prescott K. Turner, Jr. Language Processors, Inc. 959 Concord St., Framingham, MA 01701 USA (508) 626-0006 UUCP: uunet!lpi!pkt Internet: pkt@lpi.liant.com