Results 1 to 3 of 3
Thread: dynamic_cast in RTTI C++
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
08-19-2010 #1
- Join Date
- May 2009
- Posts
- 21
dynamic_cast in RTTI C++
What is the difference between dynamic_cast and static_cast
First I have searched in net. But I didn't the right one. So, I am posting here.
Thanks in Adavance,
MAdhu
-
08-20-2010 #2
dynamic_cast checks the known type information for the instance pointed at - if the instance could be of the type requested, a pointer to that type is returned. Otherwise it returns NULL. You'd usually use dynamic_cast to change a pointer to a class instance to another class in the instance's class heirarchy.
static_cast just changes the type without making checks to see if anything is valid.
If this is a homework question, then please disregard my answer and go ask your professorLinux user #126863 - see http://linuxcounter.net/
-
08-21-2010 #3
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
- Posts
- 14,038
Of course, you can also do dynamic_cast<Type&> in which case you must be prepard to catch( bad_cast ). Sometimes books are better than the net for such stuff. Check out Bjarne Stroustrup's "C++ Programming Language". It will set you back about $65-$70 USD on Amazon.com.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!