Virtual functions is the part of polymorphism.
Polymorphism is the property of Object Oriented Programming language. According to it, objects of different classes can respond to the same message.
In it, the pointer to base class is used to refer to the all objects of the derived class.
lets write a simple program to understand the concept of virtual functions.
The program uses the virtual function and lets see it output.
class A
{
public:
virtual void output()
{
coutoutput(); //calls A class output function
coutoutput(); //calls B class output function
return 0;
}
Its output will be:
Pointer point to A class object
it is A class
A class pointer point to B class object.
it is B class

Technorati Tags: 









