🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Q : dynamic_cast<>()

#3774
From: Steve Clamage
Date: Fri, 22 Mar 1996 02:24
34 lines
2027 bytes
In article RAA26760@florin.msk.su, "Dmitry M. Potapov" <dima@florin.msk.su>
writes:
>When bad_casting to pointer type, 
>dynamic_cast<>() returns NULL.
>
>Is there a standard on good_casting,
>I mean is it normal if dynamic_cast changes pointer,
>and could dynamic_cast<>() be implemented w/o changing
>the pointer if the cast was not bad ?

No cast changes a pointer. A cast yields a value based on an existing
pointer value. The new value might be the same or different, but the
original pointer is not changed.

Example, assuming each class has virtual functions:
	class B1 { int i; ... };
	class B2 { int j; ... }
	class D : B1, B2 { int k; ... };

Given a D*, you can cast the value to either a B1* or a B2*. One of
the results might be the same as the original, but they cannot both be
the same.

Similarly, given a B1* and a B2*, you can cast either value to a D*.
The result of one of the casts might be the same as the original value,
but they cannot both be the same as the original. 
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Technical Details
Message-ID: <4isusi$flo@engnews1.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <199603211714.RAA26760@florin.msk.su>

Show Full Headers
Complete Article Headers
From: clamage@Eng.Sun.COM (Steve Clamage)
Message-ID: <4isusi$flo@engnews1.Eng.Sun.COM>
X-Original-Date: 22 Mar 1996 01:13:54 GMT
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 22 Mar 96 02:24:21 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: Q : dynamic_cast<>()
Organization: Sun Microsystems Inc.
References: <199603211714.RAA26760@florin.msk.su>
Reply-To: clamage@Eng.Sun.COM
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMVIPY+EDnX0m9pzZAQErnAF/fXUOB9kzkkUV+3xD+EyRFe170csYROxa
 dDsK84Ht/96VwMWN+Sqi8r6/UE8AvrQu
 =3mSj