LearnFrenzy
Sign in Take a free test

OOPS Concepts · OOPS Concepts MCQ · Question 13

How is a virtual function call resolved? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

A Base* points to a Derived object that overrides virtual f(). Which f() does p->f() call?

  • A Base::f(), because p is a Base*
  • B Derived::f(), chosen at run time from the actual object type Correct
  • C Both
  • D It does not compile
Correct Answer: Option B

That is dynamic binding. Without virtual, the call would be resolved at compile time from the pointer type and call Base::f().

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links