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.

What could cause a dynamic_cast to crash?

I have a piece of code looking like this : TAxis *axis = 0; if (dynamic_cast<MonitorObjectH1C*>(obj)) axis = (…

c++ crash casting dynamic-cast
ClassCastException

i have two classes in java as: class A { int a=10; public void sayhello() { System.out.println("class A"); } } class …

java casting classcastexception dynamic-cast
c++ dynamic_cast error handling

Is there any good practice related to dynamic_cast error handling (except not using it when you don't have to)? …

c++ dynamic-cast
dynamic_cast fails

I have a base class and a derived class. Each class has an .h file and a .cpp file. I …

c++ dynamic-cast
How does dynamic_cast work?

If you had the following: class Animal{}; class Bird : public Animal{}; class Dog : public Animal{}; class Penguin : public Bird{}; class …

c++ dynamic dynamic-cast
java: combined instanceof and cast?

(Please no advise that I should abstract X more and add another method to it.) In C++, when I have …

java casting instanceof dynamic-cast
FAQ: Why does dynamic_cast only work if a class has at least 1 virtual method?

This does not compile in C++: class A { }; class B : public A { }; ... A *a = new B(); B *b = dynamic_cast&…

c++ dynamic-cast c++-faq
How is dynamic_cast implemented

Consider this simple hierarchy: class Base { public: virtual ~Base() { } }; class Derived : public Base { }; Trying to downcast Base* p to Derived* …

c++ dynamic-cast
How does dynamic_cast fail?

According to what I read, performing a wrong run-time dynamic_cast can either throw a bad_cast exception or return …

c++ casting dynamic-cast