🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Add dynamic_cast<type_info&>

#1933
From: Etay Bogner
Date: Fri, 08 Sep 1995 21:16
42 lines
2525 bytes
In article <MATT.95Sep8112137@physics2.Berkeley.EDU>,
fjh@munta.cs.mu.OZ.AU (Fergus Henderson) wrote:

>> I already know that the static type of `dynamic_cast<T*>(p)' is `T*',
>> because `dynamic_cast<T*>(p)' is already part of standard C++.
>> What I am asking about is the static type of your newly proposed syntax
>> `dynamic_cast<bar>(foo)', where `bar' is a value of type type_info, not
>> a type.
>> 
>> I think your idea doesn't make sense, because there *isn't* any sensible
>> static type for that expression.  Since C++ is a statically typed language,
>> every expression must have a static type, but that expression can't have
>> one.  Therefore it doesn't work in C++.

The sensible static type for that expression will be a 'void*'.

I know this sounds ugly, but so does 'dynamic_cast<void*>(p)', which as
I'm sure you know, returns a pointer to the complete object, but in the
form of a void*.

The issue here is that one has the ability to 'cast-down' to the complete
object, using 'dynamic_cast<void*>(p)' ( meaning, without knowing the
complete type type) and getting a void*, but no ability to 'cast-up' ( an
implicit procedure in C++ ) without knowing the sub-type type at compile
time.

This is needed in the same cases it is needed when using the returned
pointer from 'dynamic_cast<void*>(p)', to do the inverse-operation.

Please look at another article of mine in this thread for a usage and an
implementation.

Etay.

-- Etay Bogner,
-- Etay_Bogner@mail.stil.scitex.com,
-- Scitex Corp.
-- Israel.

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <Etay_Bogner-0809952258470001@applepo13.scitex.com>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
References: <9508048102.AA810263857@mail.stil.scitex.com> <MATT.95Sep7112147@physics10.Berkeley.EDU> <Etay_Bogner-0809950030420001@applepo11.scitex.com> <MATT.95Sep8112137@physics2.Berkeley.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: Etay Bogner <Etay_Bogner@mail.stil.scitex.com>
Newsgroups: comp.std.c++
Subject: Re: Add dynamic_cast<type_info&>
Date: 8 Sep 1995 21:16:47 GMT
Organization: Scitex Corp.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <Etay_Bogner-0809952258470001@applepo13.scitex.com>
References: <9508048102.AA810263857@mail.stil.scitex.com> <MATT.95Sep7112147@physics10.Berkeley.EDU> <Etay_Bogner-0809950030420001@applepo11.scitex.com> <MATT.95Sep8112137@physics2.Berkeley.EDU>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: applepo13.scitex.com
X-Nntp-Posting-Host: applepo13.scitex.com
Content-Length: 1523
X-Lines: 38
Originator: clamage@taumet