I have the following class hierarchy:
class A {
virtual void blah() = 0;
};
class B {
virtual void gah() = 0;
};
class C: public A, public B {};
class D: public C {
gah() {}
blah() {}
};
If I do the following:
A *something = new D();
auto a = dynamic_cast<B *>(something);
if(a == nullptr) std::cout << "NULL" << std::endl;
It prints "NULL" in the context of the program I am running (I simplified the code so that it is easily read). This suggests that the dynamic cast failed.
But if I do:
A *something = new D();
auto a = dynamic_cast<C *>(something);
auto b = dynamic_cast<B *>(a);
if(a == nullptr) std::cout << "NULL" << std::endl;
It won't print "NULL" and the dynamic_cast succeeds. Any idea why this would be the case? I thought about inlining, but I made sure every class had a virtual destructor and generated an object file.
Also please excuse any small syntax errors, the idea should be clear.