🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Virtual functions make casts faster
  2. B.It uses run-time type information stored with polymorphic classes to check the real type
  3. C.Without virtual functions, all casts are illegal
  4. 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 →