I'd like to know when dynamic_cast must or should be used over static_cast, with examples. I've read this SO question, but it doesn't really provide any concrete examples. I am assuming most examples will involve polymorphic class types. Currently the only reason I know to use dynamic_cast over static_cast is if I am not 100% sure of the concrete type I am working with.
Some other thoughts:
- Casting sideways (in multiple inheritance)
- Casting up to a base class in a virtual inheritance hierarchy
- Will the pointer change (if using static_cast) when casting to the "right most" inherited types in a class that uses multiple inheritance?
Is the "if the type is not known" reason the only reason? If not, could someone provide examples that demonstrate why dynamic_cast must or should be used over static_cast?