Thats the reason:
class x
{
public:
void DoJob()
{
show();
}
virtual void show()
{
cout<<"Base show()"<<endl;
}
};
class y:public x
{
public:
void show()
{
cout<<"Class y show()";
}
};
int main()
{
y ob1;
ob1.DoJob();
getch();
return 0;
}
After the job - the
show()
of class y is called. So you can override functions to implement a different behaviour on a virtual function call.
Regards.