What is the purpose of declaring a member function virtual in C++?
-
A
To stop derived classes from redefining it
-
B
To force the function to be inlined everywhere
-
C
To hide the function from other translation units
-
D
To allow dispatch at runtime through a base pointer
Correct answer
Correct answer
D. To allow dispatch at runtime through a base pointer
14 views
Explanation
A virtual function is selected at run time from the dynamic type of the object, which enables polymorphism.
Reference
Asked in: NTS, PPSC IT, Campus Interviews
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ