Sunday, February 27, 2011

Virtual Functions


#include
#include
class base
{
public :
virtual void show()=0;
      /* {
cout<<"\n Base Class ";
}*/
};

class drived1:public base
{
public:
void show()
{
cout<<"\n Drived 1";
}
};

class drived2:public base
{
public:
void show()
{
cout<<"\n Drived 2";
}
};

void main()
{
clrscr();
base *ptr;

// base obj;
drived1 d1;
drived2 d2;

d1.show();
// obj.show();

ptr=&d1;
ptr->show();

ptr=&d2;
ptr->show();

       getch();
}

No comments:

Post a Comment