Topic: static_cast & dynamic_cast (was: downcasting problem)


Author: matt@godzilla.EECS.Berkeley.EDU
Date: 1995/07/04
Raw View
In article <3t1q0b$pmo@hermes.synopsys.com> jbuck@synopsys.com (Joe Buck) writes:

> For this and other questions about the motivations for why certain
> features are in the language and why changes have been made, I think
> that Stroustrup's book "The Design and Evolution of C++" is the best
> source.  It's very readable and understandable.
>
> (Then you'll find out about the other two cast types, const_cast and
> reinterpret_cast).

I second the recommendation of Design and Evolution: it's an excellent
answer to many of the "why" questions about C++.  Its only real flaw
is that it precedes the new version of the C++ standard library, the
one in which templates are all-pervasive.  The new standard library
points C++ programming in a radically new direction, and I hope that
a future edition of Design and Evolution will address that.

That said, though, there is a very simple answer to the question about
static_cast, dynamic_cast, const_cast, and reinterpret_cast: casts, as
introduced in C, have always had several different meanings.  It's
always a potential source of confusion when a single syntactic form
is used for several different purposes, it's worse when that form
doesn't have a very distinctive syntax, and it's still worse when
some of the meanings are safe and others are dangerous.  The reason
for introducing the four new casting keywords is so that different
operations will have different names.
--
Matt Austern          matt@physics.berkeley.edu
http://dogbert.lbl.gov/~matt





Author: devitto@london.sinet.slb.com (Dom De Vitto)
Date: 1995/06/30
Raw View
Jim Heliotis (heliotis.roch803@xerox.com) wrote:
> I have read some material describing how static_cast and dynamic cast work.
> However, my understanding of the motivation behind them is not deep enough, and
> I think this is preventing me from really understanding what they are all about,
> how they would work, and when I should use them.

> Can anyone direct me to some literature that would help me? Please don't suggest
> the Draft Standard or the ARM. That's where my information has come from so far.

>      Thanks,
>      Jim
The Design and Evolution of C++ by Bjarne Stroustrup.


> ============================================================================
> Jim Heliotis                                       Voice Phone: 716-383-7383
> Xerox Corporation                                   FAX Phone:  716-383-7395
> 435 W. Commercial St.                                     Mail Stop: 803-01A
> East Rochester, NY 14445              Electronic Mail: JEH.ROCH803@Xerox.COM
> ============================================================================







Author: jbuck@synopsys.com (Joe Buck)
Date: 1995/06/30
Raw View
heliotis.roch803@xerox.com writes:
> I have read some material describing how static_cast and dynamic cast
> work.  However, my understanding of the motivation behind them is not
> deep enough, and I think this is preventing me from really understanding
> what they are all about, how they would work, and when I should use
> them.  Can anyone direct me to some literature that would help me?
> Please don't suggest the Draft Standard or the ARM. That's where my
> information has come from so far.

For this and other questions about the motivations for why certain
features are in the language and why changes have been made, I think
that Stroustrup's book "The Design and Evolution of C++" is the best
source.  It's very readable and understandable.

(Then you'll find out about the other two cast types, const_cast and
reinterpret_cast).



--
-- Joe Buck  <jbuck@synopsys.com> (not speaking for Synopsys, Inc)
Phone: +1 415 694 1729





Author: heliotis.roch803@xerox.com (Jim Heliotis)
Date: 1995/06/28
Raw View
I have read some material describing how static_cast and dynamic cast work.
However, my understanding of the motivation behind them is not deep enough, and
I think this is preventing me from really understanding what they are all about,
how they would work, and when I should use them.

Can anyone direct me to some literature that would help me? Please don't suggest
the Draft Standard or the ARM. That's where my information has come from so far.

     Thanks,
     Jim



============================================================================
Jim Heliotis                                       Voice Phone: 716-383-7383
Xerox Corporation                                   FAX Phone:  716-383-7395
435 W. Commercial St.                                     Mail Stop: 803-01A
East Rochester, NY 14445              Electronic Mail: JEH.ROCH803@Xerox.COM
============================================================================