It's not going to be a long talk, for example.
Class fruit
{
Public
void Func ()
{
printf ("fruit\n");
}
virtual void Vfunc ()
{
printf ("v fruit\n");
}
};
Class Apple:public Fruit
{
Public
void Func ()
{
printf ("apple\n");
}
void Vfunc ()
{
printf ("v apple\n");
}
};
int main (int argc, char* argv[])
{
fruit* f = new Apple (); Note that F is the parent class pointer
F->func ();
F->vfunc ();
return 0;
}
The result is:
Fruit
V Apple
In the example, Func uses a function overlay
Vfunc uses a virtual function
When a pointer to the fruit class points to an object of an Apple class, Func invokes the function of the parent class, and Vfunc calls the function of the child class.
If the function overrides, call the member function, directly call the object pointer to the member function of the class, the example is fruit
virtual function, when a member function is called, a member function that points to the owning class of the object is called, as in the example Apple
Why should C + + overwrite (Learn notes)