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 »

If you still didn't find what you're looking for, you can search this website below: