Friday, 19 October 2012

Program Of Pure Virtual Function In C++

#include< iostream.h>
#include< conio.h>
{
protected :
int a,b;
public:
{ 
cout<< "\nEnter two 'int' values::";
cin>>a>>b;
} 

}; 
class xyz:public abc
{
public:
void display()
{
cout<< "\nSum for 1st derived class="<< a+b;
}
};
class mn:public abc
{
public:
void display()
{
cout<< "\nSum for 2nd derived class:"<< a+b;
}
};
void main()
{
clrscr();
xyz ob;
mn ob1;
abc *ptr;
ptr=&ob;
cout<< "\nFor object of 1st derived class."<< endl;
ptr->display();
cout<< "\nFor object of 2nd derived class."<< endl;
ptr=&ob1;
ptr->take();
getch();
}

--------------------------------------------------------------------------------------------------

Pure  Virtual Function

In object-oriented programming, a  virtual method is a function or method whose behaviour can be overridden within an inheriting class by a function with the same signature. This concept is a very important part of the polymorphism portion of object-oriented programming (OOP).


by:---http://en.wikipedia.org/wiki/Virtual_function




No comments:

Post a Comment