Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!cs.umn.edu!kksys!wd0gol!rathe!ian From: ian@rathe.cs.umn.edu (Ian Hogg) Newsgroups: comp.lang.c++ Subject: Re: Inheritance & type conversion Message-ID: <1991Jun6.140159.9208@rathe.cs.umn.edu> Date: 6 Jun 91 14:01:59 GMT References: <2348@taurus.cs.nps.navy.mil> Organization: Rathe, Inc. Lines: 56 In article <2348@taurus.cs.nps.navy.mil> skip@taygeta.oc.nps.navy.mil (Skip Carter) writes: > > I have been programming C++ for the past few months, using Turbo C++ > V1.0 and Zortech C++ V2.1. In the process of writing an application > I came across the following behaviour, which I don't understand: > > > 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. You don't need to define a conversion from Derived to Base. An object of type derived can be used anywhere an object of base is expected. > > Base has friends functions, report1 and report2. Report1 takes a > reference to a Base, report2 takes the value of a Base, > as the parameter. > > The following: > > Derived dtype; > > report1( dtype ); > > causes a conversion to Base then report1 is invoked with Turbo C++, > but for Zortech C++ NO CONVERSION occurs. > > > BUT: > > Derived dtype; > > report2( dtype ); > > > cases a conversion to Base with Zortech C++, BUT NOT for Turbo C++ > > > > > I am too much of a novice to be able to figure out which is the > correct behavior. Can anyone give me some insight ? I have attached > a copy of the simple program. > I don't know which is correct but I would expect no conversion to take place in either place. The compiler should only apply conversions whenever necessary, and they aren't in this case. -- Ian Hogg email: rathe!ian@cs.umn.edu ...!umn-cs!rathe!ian Rathe, Inc ianhogg@cs.umn.edu 366 Jackson Street phone: (612) 225-1401