dynamic_cast
only supports pointer and reference types. It returns NULL
if the cast is impossible if the type is a pointer or throws an exception if the type is a reference type. Hence, dynamic_cast
can be used to check if an object is of a given type, static_cast
cannot (you will simply end up with an invalid value).
C-style (and other) casts have been covered in the other answers.