VIRTUAL FUNCTIONS


SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class base
{
 public:
    virtual void show()
    {
       cout<<"\n Show base";
    }
    void display()
    {
       cout<<"\n Display base";
    }
 };

 class derived:public base
{
 public:
    void show()
    {
       cout<<"\n\n Show derived";
    }
    void display()
    {
       cout<<"\n\n display derived";
    }
 };

 void main()
{
 derived D;
 base B;
 clrscr();
 base *p;
 p=&B;
 p->show();
 p->display();
 p=&D;
 p->show();
 p->display();
 getch();
}

OUTPUT:

 Show base
 Display base

 Show derived
 Display base
Previous
Next Post »

Still not found what you are looking for? Try again here.