🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Dmitry M. Potapov Thu, 21 Mar 1996 23:52
Q : dynamic_cast<>()
#3767
Author: Dmitry M. Potapov
Date: Thu, 21 Mar 1996 23:52
20 lines
1321 bytes
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 ?

Thanks in advance,

Potapov Dmitry, dima@florin.msk.su
-- 



[ 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                             ]
Re: Q : dynamic_cast<>()
#3774
Author: 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                             ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads