Possible Duplicate:
Regular cast vs. static_cast vs. dynamic_cast
I learned how static_cast works by this question. Why is it important to use static_cast instead of reinterpret_cast here?
But if static_cast does knows classes' inheritance-relationship, why does dynamic_cast exist? And when do we must use dynamic_cast?
I'll post a simple example of how they differ:
If I understand correctly,
static_cast
only knows the type it's casting to.dynamic_cast
on the other hand knows type being cast, along with the type being cast to.