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.

error: cannot dynamic_cast ... (target is not pointer or reference)

I'm learning exception handling in C++ and run into a problem. Here's the code: #include<iostream> #include<…

c++ exception try-catch dynamic-cast
dynamic_cast across a shared_ptr?

I have two classes A and B, B inherits from A. If I have a shared_ptr<A> …

c++ polymorphism shared-ptr dynamic-cast
C++: "... is not a polymorphic type" while using boost::dynamic_pointer_cast

Why do I receive the following error for the following code? 1>C:\Libs\boost_1_44\boost/smart_ptr/shared_ptr.…

c++ compiler-errors shared-ptr dynamic-cast
How to identify failed casts using dynamic_cast operator?

Scott Meyer in his book Effective C++ says dynamic_cast is used to perform safe casts down or across an …

c++ pointers reference dynamic-cast
When dynamic_cast will throw exception in case used with pointer?

I am using dynamic_cast in my source to cast pointer as some thing like below, Base *base = here storing …

c++ dynamic-cast
cast const Class using dynamic_cast

I want to cast this: class Base { public: virtual ~Base(){}; }; class Der : public Base {}; int main() { const Base* base = new …

c++ constants dynamic-cast
Portably safe to pass NULL/zero to dynamic_cast?

Out of habit for checking null pointers, I have sometimes written: MyClass * c = someBasePtr ? dynamic_cast<MyClass*>(someBasePtr) : 0; …

c++ null dynamic-cast
dynamic_cast with RTTI disabled

I'm curious to know what happens when compiling code with a dynamic cast whith RTTI disabled (either with -fno-rttion GCC …

c++ rtti dynamic-cast
C++ dynamic_cast - polymorphic requirement and downcasting

In the following code, while constructing obj in case 1, we construct a derived class object too, but its member functions …

c++ dynamic-cast downcast
Accessing subclass members from a superclass pointer C++

I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit from Student, and all the instances …

c++ inheritance virtual-functions dynamic-cast static-cast