Pure Virtual Function

When we use same function name in both base class(parents class, super clas) and derived class
(child class, sub class), the function in base class is declared as virtual using the keyword virtual.
A virtual function, equated to zero(function name()=0) is called a pure virtual function.


#include<iostream.h>
#include<conio.h>
class a
{
public:
virtual void disp()=0; //pure virtual function
};
class b: public a  //class b inherits class a
{
public:
void disp()
{
cout<<"hello";
}
};
class c:public a//class c inherits a class
{
public:
void disp()
{
cout<<"good";
}};
void main()
{
clrscr();
b ob1;  //ob1 is the object of b class
c ob2;   //ob2 is the object of c class
ob1.disp();
ob2.disp();
getch();
}

pure virtual function
    Explaination
In above example we create 3 classes, class a is the base class and class b and c are the derived class.
Here, virtual void disp()=0; means "do-nothing" function and such functions are called pure virtual
functions.