Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    dynamic_cast in RTTI C++

    In what situations we have to use RTTI dynamic_cast mechanism.
    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,

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Nottingham, England
    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 professor
    Linux user #126863 - see

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    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
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts