🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: the most dissatisfying part of c++

#244
From: Jonathan Shapiro
Date: Thu, 02 Aug 1990 18:17
37 lines
1518 bytes
In article <27634@netnews.upenn.edu>, limsoon@saul.cis.upenn.edu
(Limsoon Wong) writes:

> the program below is a contrived one.   it cannot  be compiled.
> the reason is a type fault. however, it exhibits a very central
> characteristic of update.    something should be  done to allow
> this kinds of programs.	   			    ---limsoon.
> 
> 
> 
> #include <stream.h>
> class a { 
>   public: 
>     a& test() { 
> 	// do some modification to the state of this object,
> 	// then ...
> 	return *this;
> };
> class b : public a { 
>   public:
>     int b;
> };
> main() { 
>   b B; 
>   B = B.test();
>   // type violation despite the fact that 
>   // `B' and `B.test()' are the same object.
> }

This has surprising consequences in the face of virtuals, since the
caller thinks they are getting an instance of an A, not a B.  From a
static typechecking angle it works, and the parallel argument for
returning pointer to derived in place of pointer to base follows.

However, in the face of multiple inheritance this doesn't work at all.

Jon
Technical Details
Message-ID: <11296@odin.corp.sgi.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!decwrl!sgi!shinobu!odin!thebeach.wpd.sgi.com!shap
References: <27634@netnews.upenn.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!decwrl!sgi!shinobu!odin!thebeach.wpd.sgi.com!shap
From: shap@thebeach.wpd.sgi.com (Jonathan Shapiro)
Newsgroups: comp.std.c++
Subject: Re: the most dissatisfying part of c++
Message-ID: <11296@odin.corp.sgi.com>
Date: 2 Aug 90 18:17:18 GMT
References: <27634@netnews.upenn.edu>
Sender: news@odin.corp.sgi.com
Reply-To: shap@sgi.com
Organization: Silicon Graphics, WorkGroup Products Division
Lines: 37