← Quiz: Type Casting in C++: all 10 questions
Quiz: Type Casting in C++ · Question 4 of 10
Why does dynamiccast need the base class to have at least one virtual function?
Why does dynamic_cast need the base class to have at least one virtual function?
- A.Virtual functions make casts faster
- B.It uses run-time type information stored with polymorphic classes to check the real type
- C.Without virtual functions, all casts are illegal
- D.Because dynamic_cast calls the virtual function
Answer & explanation
Correct answer: It uses run-time type information stored with polymorphic classes to check the real type
Only polymorphic classes carry the type information that the run-time check reads.
Can you get the rest right without peeking?
Take the timed Quiz: Type Casting in C++ quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →