Although it is difficult to find a C + + book or magazine that does not discuss polymorphism, most of these discussions make it difficult to use polymorphism and C + + virtual functions. In this article, I intend to make the reader understand the virtual function implementation technology in C + + from several aspects and combine some examples. To illustrate, write this article just want to exchange learning experience with you because I have a shallow knowledge, there are some mistakes and deficiencies, I hope everyone criticized and corrected, in this deep thank you.
I. Basic CONCEPTS
First, C + + realizes polymorphism through virtual functions. " Regardless of the class in which the message is sent, they send a message with the same form, and the handling of the message may change with the object of the takeover message "The way it is called polymorphism." "In the hierarchy of a class built on a base class, you can invoke a procedure of the same name in the object of any derived class, and the process provided by the invoked procedure can change with the class to which it belongs. The virtual function is first a member function that can be redefined in the derived class of the class and given another processing function.
Second, the definition of virtual function and the redefinition of 01 in the derived class. Class class Name {public:03. virtual member function description; 04.} 05.06. Class Name: base class Name {public:08. virtual member function description; 09.}
Three, the structure of virtual function in memory
1. Let's take a look at an example: 01.