Explain the need of a pure virtual function.

 
 

A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation of their own. A pure virtual member function specifies that a member function will exist on every object of a concrete derived class even though the member function is not (normally) defined in the base class. This is because the syntax for specifying a pure virtual member function forces derived classes to implement the member function if the derived classes intend to be instantiated.
For example:
class Shape
{
public:
void draw () = 0; //pure virtual function
};
The function draw () is a pure virtual function and the class Shape is an abstract class. Pure virtual member functions allow users to write code against an interface for which there are several functionally different variants. This means that semantically different objects can be passed to a function if these objects are all under the umbrella of the same abstract base class.

Re: Explain the need of a pure virtual function.

virtual member function has no body and it is initlized to 0 and it must be overridden in sub class then it is said to be pure virtual fun.
imporatance:
some times we can mention only the function name and it is not possible to define function body in that cases we use this function