A: While derived class overrides the base class method through redefining the same function, then if client wished to access redefined the method from derived class via a pointer from base class object, then you have to described this function in base class as virtual function.
class parent
{
void Show()
{
cout << "i''m parent" << endl;
}
};
class child: public parent
{
void Show()
{
cout << "i''m child" << endl;
}
};
parent * parent_object_ptr = new child; parent_object_ptr->show() // calls parent->show() now we goto virtual world...
class parent
{
virtual void Show()
{
cout << "i''m parent" << endl;
}
};
class child: public parent
{
void Show()
{
cout << "i''m child" << endl;
}
};
parent * parent_object_ptr = new child;
parent_object_ptr->show() // calls child->show()