Virtual Base Class

in Hindi - Virtual Base Class



not yet

Source Code :

RUN#include<iostream.h>
#include <conio.h>

class base 
{
public :
virtual void display()
{
cout<<"
Displaying from base class";
}
};
class derived1 : public base
{
public :
void display()
{
cout<<"
Displaying from 1st derived class";
}
};
class derived2 : public base
{
public :
void display()
{
cout<<"
Displaying from 2nd derived class";
}
};
int main(){

base b1;
derived1 d1; 
derived2 d2;
base *bptr;
cout<<"
Base class pointer pointing to base class object";
bptr=&b1;
bptr -> display();
cout<<"
Base class pointer pointing to first derived class object";
bptr=&d1;
bptr -> display();
cout<<"
Base class pointer pointing to second derived class object";
bptr=&d2;
bptr -> display();

return 0;
}