🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #860

Re: Co-ordinating the polymorphism in C++

#860
From: Desmond Dsouza
Date: Mon, 25 Feb 1991 22:10
41 lines
2624 bytes
craig@gpu.utcs.utoronto.ca (Craig Hubley) writes:

	>   >1 Redefining acceptable arguments to be pointers to derived classes
	>   >  (I'm assuming thats what you meant) instead of to base classes will
	>   >  break strong typing.
	>
	>   No, the opposite.  You can *generalize* arguments but not *specialize*
	>   them without risking failures.  The derived virtual may try to use aspects
	>   of the derived type it expects, when only the base type is there, since
	>   that was what the original base virtual expected, and that was what
	>   programmers provided.  That would be equivalent to automatically casting
	>   B* to D*... which C++ doesn't do.
	>

OK, what you want would be type safe (arguments are contravariant).

There was recently a long discussion on this in comp.object. Bertrand
Meyer claimed that few cases, if any, need a derived class to have
*more* general arguments than its base class, and used this to support
co-variance instead of contravariance. If you have convincing examples
which do need contravariance, could you post them?

Note also that implementing this could also mean change to function
call/return sequences, specially with the cfront implementation of
multiple-inheritance, where converting Derived to Base pointers
involves run-time checks and offsets. Multiple compiler-generated
versions of functions, or multiple entry points, can eliminate the
overhead of this when it is not used. 

Returning a pointer (reference) to a derived class instead of a base
class is definitely useful, though it has similar effects on
implementation efficiency in call/returns.

--
Desmond.
--

-------------------------------------------------------------------------------
 Desmond D'Souza, MCC CAD Program | ARPA: dsouza@mcc.com | Phone: [512] 338-3324
 Box 200195, Austin, TX 78720 | UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!dsouza
Technical Details
Message-ID: <DSOUZA.91Feb25161042@optima.cad.mcc.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!milano.sw.mcc.com!cadillac!dsouza
References: <1991Feb11.003849.27340@gpu.utcs.utoronto.ca> <600@taumet.com> <DSOUZA.91Feb14151948@optima.cad.mcc.com> <1991Feb16.114422.14266@gpu.utcs.utoronto.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!milano.sw.mcc.com!cadillac!dsouza
From: dsouza@optima.cad.mcc.com (Desmond Dsouza)
Newsgroups: comp.std.c++
Subject: Re: Co-ordinating the polymorphism in C++
Message-ID: <DSOUZA.91Feb25161042@optima.cad.mcc.com>
Date: 25 Feb 91 22:10:42 GMT
References: <1991Feb11.003849.27340@gpu.utcs.utoronto.ca> <600@taumet.com>
 <DSOUZA.91Feb14151948@optima.cad.mcc.com>
 <1991Feb16.114422.14266@gpu.utcs.utoronto.ca>
Sender: news@cadillac.CAD.MCC.COM
Followup-To: comp.std.c++
Distribution: na
Organization: MCC CAD Program, Austin, Texas
Lines: 41
In-reply-to: craig@gpu.utcs.utoronto.ca's message of 16 Feb 91 11:44:22 GMT