Top "Dynamic-cast" questions

The dynamic_cast conversion allows for safely converting pointers (and references) to classes up, down, and sideways in the inheritance hierarchy.

dynamic cast with interfaces

I have a class with implements 2 interfaces and inherits 1 class. So, generally it looks like this: class T : public A, …

c++ casting dynamic-cast
How expensive are dynamic casts in C++?

For my GUI API which works with a variety of backends (sdl, gl, d3d, etc) I want to dynamically …

c++ dynamic-cast
`dynamic_cast` from Base to Derived

Yes, I know that downcast using dynamic_cast can't compile if the Base is not polymorphic, but my problem is …

c++ dynamic-cast
how to check whether two pointers point to the same object or not?

Consider two pointers A* a; B* b; Both A and B are polymorphic classes. How to check whether a and …

c++ dynamic-cast
When is static cast safe when you are using multiple inheritance?

I found myself in a situation where I know what type something is. The Type is one of three (or …

c++ dynamic-cast static-cast
Can not use dynamic_cast to a const object

I want to write a method where a Base object pointer will be passed as a parameter, and inside the …

c++ constants dynamic-cast const-cast
Downcasting using dynamic_cast returns null

I'm trying to cast a base class object to a derived class object with dynamic_cast, but dynamic_cast returns …

c++ dynamic-cast downcast
Why is dynamic_cast evil or not ? Should I use dynamic_cast in this case?

Some say the use of dynamic_cast often means bad design and dynamic_cast can be replaced by virtual functions …

c++ rtti dynamic-cast
In C++ check if two instances of a base class are infact of the same subclass

The below code explains the problem. Fill in same_sub_class to detect if the two pointers to virtual base …

c++ dynamic-cast
Smart pointers and dynamic_cast

I apologize in advance if this was answered already as I looked and could not find the answer. NOTE: this …

c++ polymorphism smart-pointers dynamic-cast