A pure virtual function is to force the derived class to overrride it. What it measn is that you cannot call the pure virtual method using an object of the class that declares the pure virtual method or using an object of a derived class that inherits the method.
Suppose you design a class and you want everyone to have an Open() method.
-
class MyClass
-
{
-
virtual void Open();
-
};
-
So, everybody derives form MyClass and implements an Open() method. All except the doofus in the last cubicle who implements a Start() method instead and refuses to write an Open() method.
By coding:
-
class MyClass
-
{
-
virtual void Open() = 0;
-
};
-
any class without an Open() method will inherit the pure virtual function. Therefore, objects of those classes cannot call the Open() method.
The compiler enforces this by not allowing objects to be created using classes that have pure virtual funcitons or that have inherited pure virtual functions.
Now the codeof the doofus won't compile until an Open method is implemented.
Class designers use these pure virtual functions to tell you what you must implement in your class.