Which of the following is an example of a class with a pure virtual function in C++?
Question
Which of the following is an example of a class with a pure virtual function in C++?
Solution
A class with a pure virtual function in C++ is known as an abstract class. Here is an example:
class AbstractClass {
public:
// A pure virtual function
virtual void pureVirtualFunction() = 0;
};
In this example, AbstractClass
is a class with a pure virtual function pureVirtualFunction()
. The = 0
after the function declaration means that the function is pure virtual, and it makes AbstractClass
an abstract class.
An abstract class cannot be instantiated, and it is meant to be subclassed. Subclasses of an abstract class must implement all its pure virtual functions.
Similar Questions
Which of the following is an example of runtime polymorphism?Function overloadingOperator overloadingVirtual functionsInline functions
In C++, polymorphism requires :Inheritance onlyVirtual functions only References onlyInheritance, Virtual functions and reference
2. Which of the following gets called when an object is being created?A. ConstructorB. Virtual FunctionC. DestructorsD. Main
Which function is automatically called in C++ if we do not define it in a class?
Which of the following is true about constructors. 1) They cannot be virtual. 2) They cannot be private. 3) They are automatically called by new operato
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.