Difficulty: Easy
Correct Answer: virtual void Display(void) = 0;
Explanation:
Introduction / Context:
In C++, a pure virtual function is a function in a base class that has no implementation in that class and must be overridden in derived classes. Declaring a pure virtual function makes the class abstract, meaning you cannot instantiate it directly. This question tests your ability to recognize the precise syntax that the C++ language uses to mark a virtual member function as pure (abstract).
Given Data / Assumptions:
Concept / Approach:
The correct form for a pure virtual member function is: return_type function_signature = 0; combined with the virtual keyword in the class definition. The “= 0” portion is not an assignment; it is grammatically special and tells the compiler that the function has no definition in the current class and must be overridden (unless the derived class is also abstract). You may still provide an out-of-class definition for a pure virtual function in rare cases, but the class remains abstract until all pure virtuals are overridden in a concrete derived class.
Step-by-Step Solution:
Verification / Alternative check:
Attempting to instantiate a class containing at least one pure virtual function results in a compile-time error. A derived class that overrides Display with an exact-matching signature becomes instantiable provided no other pure virtuals remain unimplemented.
Why Other Options Are Wrong:
virtual void Display(void){0}; — A function body with “{0}” is not the pure-virtual syntax; it attempts a definition.
virtual void Display = 0; — Missing the parameter list; not a valid member function declaration.
void Display(void) = 0; — Missing virtual; the pure marker applies to virtual functions only.
Common Pitfalls:
Final Answer:
virtual void Display(void) = 0;
Discussion & Comments