Sunday, May 11, 2014

Program to display input value using virtual function with class in C++



//program to print out input value using virtual function with class

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

class Base
{
public:
int a;
virtual void display()                                
{
}
};

class Derived:public Base
{
public:
virtual void display()
{
cout<<"Enter a Value of a:";
cin>>a;
cout<<"Value of a is :"<<a;
}
};

int main()
{
Base *pt;
Derived b1;
pt=&b1;
(*pt).display();//pt->display();
getch();
}


No comments:

Post a Comment