Recall & Review
beginner
What is a pure virtual function in C++?
A pure virtual function is a function declared in a base class that has no implementation and is set to 0. It forces derived classes to provide their own implementation.Click to reveal answer
beginner
How do you declare a pure virtual function in C++?
You declare a pure virtual function by adding = 0 at the end of the function declaration inside a class, for example:
virtual void func() = 0;Click to reveal answer
beginner
What happens if a class has at least one pure virtual function?The class becomes abstract, meaning you cannot create objects of that class directly. You must derive a subclass and implement the pure virtual functions.Click to reveal answer
intermediate
Why use pure virtual functions in a base class?
They define an interface that derived classes must follow, ensuring certain functions are implemented in subclasses, which helps design flexible and extendable programs.
Click to reveal answer
advanced
Can a pure virtual function have a body (implementation) in C++?
Yes, a pure virtual function can have a body, but it still makes the class abstract. Derived classes can call the base class implementation if needed.Click to reveal answer
How do you mark a function as pure virtual in C++?
✗ Incorrect
A pure virtual function is declared by adding = 0 after its declaration inside the class.
What is true about a class with at least one pure virtual function?
✗ Incorrect
A class with at least one pure virtual function is abstract and cannot be instantiated directly.
Can a pure virtual function have an implementation in C++?
✗ Incorrect
A pure virtual function can have a body, but the class remains abstract.
Why would you use a pure virtual function?
✗ Incorrect
Pure virtual functions force derived classes to provide their own implementation.
What keyword is used to declare a pure virtual function?
✗ Incorrect
The = 0 syntax marks a function as pure virtual.
Explain what a pure virtual function is and how it affects a class in C++.
Think about how pure virtual functions create a blueprint for subclasses.
You got /4 concepts.
Describe why and when you would use pure virtual functions in your C++ programs.
Consider how pure virtual functions help organize code and design.
You got /4 concepts.