Answer the question
In order to leave comments, you need to log in
How to use dynamic_cast?
The book is not clear enough.
What is dynamic_cast for and how to use it? Can you explain in simple terms?
Answer the question
In order to leave comments, you need to log in
To safely cast a base class to a child.
Let's say you have a Base* foo pointer, which most likely points to a derived class. And you want to cast it to a derivative in order to use its functions. But there is a chance that it is not a derived class in which case you will have problems.
To avoid problems you can use dynamic_cast(foo). The cast will return nullptr if the pointer does not point to the Derived class.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question