Article View: comp.std.c++
Article #1931Re: Add dynamic_cast<type_info&>
From: Etay Bogner
Date: Fri, 08 Sep 1995 21:46
Date: Fri, 08 Sep 1995 21:46
45 lines
2461 bytes
2461 bytes
(A copy of this message has also been posted to the following newsgroups: comp.std.c++) 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:
<9509082003.AA36456@ird.scitex.com>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<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!in1.uu.net!bounce-back Date: 08 Sep 95 21:46:53 GMT Approved: fjh@cs.mu.oz.au Return-Path: <Etay_Bogner@mail.stil.scitex.com> X-Original-Date: Fri, 8 Sep 1995 23:03:42 +0300 Message-ID: <9509082003.AA36456@ird.scitex.com> From: Etay_Bogner@mail.stil.scitex.com (Etay Bogner) Subject: Re: Add dynamic_cast<type_info&> Newsgroups: comp.std.c++ References: <9508048102.AA810263857@mail.stil.scitex.com> <MATT.95Sep7112147@physics10.Berkeley.EDU> <Etay_Bogner-0809950030420001@applepo11.scitex.com> <MATT.95Sep8112137@physics2.Berkeley.EDU> Organization: Scitex Corp.