C++ Program to illustrate the use of Pure virtual function

By | January 3, 2017

Pure virtual function


Write a C++ Program to illustrate the use of  Pure virtual function. Here’s a Simple C++ Program to illustrate the use of  Pure virtual function in C++ Programming Language.


Abstract base class & pure virtual function


  • The class that is not used to create objects is called an abstract class.
  • The only purpose of an abstract class is to act as a base class.
  • An abstract class is required when the base class is unable to create a meaningful implementation for a member function.
  • For example, in the following figure, the class Shape represents the abstract concept for which objects cannot exist.
  • A Shape makes sense only as the base of some class derived from it.
  • This can be seen from the fact that it is not possible to provide sensible definitions for its virtual functions.
  • A better alternative is to declare the virtual function of the class Shape to be pure virtual functions.
  • A virtual function is made pure by the initializer, = 0. Thus, the virtual functions in the abstract base class can be made pure as:
  •   virtual void Enter_data( ) = 0 ;

  •   virtual void Area( ) = 0;

  • A class with one or more pure virtual function is an abstract, and no object of that abstract class can be created. An abstract class can be used only as an interface and as a base for other classes.

Below is the source code for C++ Program to illustrate the use of  Pure virtual function which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :



OUTPUT : :



Above is the source code and output for C++ Program to illustrate the use of Pure virtual function which is successfully compiled and run on Windows System to produce desired output.

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post….

Leave a Reply