Home » » Virtual function in C+_Program with Sample

Virtual function in C+_Program with Sample

Virtual function in C+_Program with Sample

Virtual function in C+_Program with Sample

Virtual function

#include<iostream.h>
#include<conio.h>
class Base
{
public:
virtual void Display()
{
cout<<"This is the base class virtual function"<<endl;
}
};
class Derived1:public Base
{
public:
void Display()
{
cout<<"This is the Derived1 class display function"<<endl;
}
};
class Derived2:public Base
{
public:
void Display()
{
cout<<"This is the Derived2 class display function"<<endl;
}
};
void main()
{
clrscr();
Base*b;
b=new Base;
b->Display();
b=new Derived1;
b->Display();
b=new Derived2;
b->Display();
getch();

}

0 coment�rios:

Post a Comment

Link you don't want to vouch for Read more: https://html.com/seo/#ixzz5zVltiZ5g