Pure Virtual Function are virtual functions that are assigned value of zero. They make for the characteristics of the abstract classes.
Abstract Class is a class which contains at least one pure virtual function in it.
Syntax:
Due to the virtual functions in the abstract class:
Let's look at the following example:
Couple of things to notice:
Car
and Truck
extend class Vehicle
.lines 33 and 34
the the code won't compile.
That's because objects of those classes cannot be created.Truck
class overwrites the pure virtual function
from the parent class (like in the Car
class), then Truck
object
can be created (by uncommenting line 34
).