1. Virtual Functions
Assume that people is the parent class of man. Both the people class and man class define the real function walk ()
People * p = new man ();
P-> walk ();
Here P executes the walk () function of the people class. This is different from the java language. java executes man's walk () function here. So how does C ++ rewrite the subclass method and dynamically locate the subclass method?
The virtual keyword must be used to define the walk () of the parent class and subclass ()
Virtual void walk ();
Execute p-> walk (); that is, the walk () of the subclass of the execution ().
2. Pure virtual functions
Virtual void walk () = 0; a pure virtual function is defined here, which can be implemented in the subclass instead of in the parent class.
If the walk function is not implemented in the man class
People * p = new man ();
An error is reported. The man class is an abstract class.