The compiler cannot generate code to cast from the base type to the derived if the inheritance is virtual. This is because the subobject of the virtual base class inside the descendant class object cannot calculate the address of the enclosing object at the compilation stage. But this address can be calculated at the execution stage and, therefore, such a cast can be performed by the dynamic_cast operator.
By answer options:
1. Correct, correctness is not checked
2. Correct, checked at run-time
3. Error: cast from a virtual base class. Not enough information to cast.
4. Correct. Done in runtime. There is enough information.
5. Error: cast from a virtual base class. Not enough information to cast.
6. Error: cast from a non-polymorphic base class. There is no type information on the px pointer.
Login in to like
Login in to comment