Pure Virtual Function
A pure virtual function is a category of function that has only a function declaration. That does not have the function definition. The subsequent program describes how to declare a pure virtual function
// pure virtual function
# include<iostream.h>
class base
{
private:
int x;
float y;
public:
};
virtual void getdata( );
virtual void display( );
class derivedB : public base
{
private:
int rollno;
char name[20];
public:
};
void getdata ( );
void display ( );
void base :: getdata ( )
{
}
void base :: display( )
{
}
void derivedB :: getdata ( )
{
cout <<"enter roll number \n";
cin >> rollno;
cout<< "enter name \n";
cin>> name;
}
void derivedB :: display ( )
{
cout << "roll number student's name \n";
cout << roll no << '\t' << name << endl;
}
void main ( )
{
base *ptr; derivedB obj; ptr = &obj;
ptr-> getdata ( );
ptr -> display ( );
}
Output of the program is
Enter roll number
89001
enter name ganapathy
rollnumber student's name
89001 ganapathy