Pure Virtual
Pure virtual functions are a way to force an interface in derived classes without providing an implementation.
This is useful when no reasonable default implementation exits.
A delima
You are implementing a shape class for a drawing system.
It will hold squares, triangles, ....
It seems reasonable that all shapes have a
Draw
method.
But what should the default impementation be? There is none.
The solution is to build a
pure virtual
Draw method in the base class.
Syntax
class Shape { ... virtual Draw()const = 0; }
What does this mean?
Shape
is an
abstract class
No instance of Shape can be created.
See
virtual