I have the following case in C++:
- Abstract base classes
Abstract1andAbstract2. They are unrelated. - A class
Fooderiving from bothAbstract1andAbstract2
I am in a compilation unit where I have no information about class Foo (no declaration, no definition). Only Abstract1 and Abstract2 are known.
(Actually, Foo is even defined in a DLL)
Will dynamic_cast allow casting from Abstract1* to Abstract2*? Is this a standard?
What you describe is a so-called cross-cast. For
dynamic_cast<T>(v), the standard specifies in [expr.dynamic.cast]/8That will work even with no information about
Foo's existence in the translation unit that contains the cast.You should check out this question too.