After listening to the C ++ class, I thought it was really good to remember. Write something when you think of it. (PS: The first time I had to brush the night, I was a little excited. O (∩ _ ∩) O)
Inheritance first, the relationship between is-a in many real-world languages cannot be used as a criterion in programming. Specifically, we need to meet the Rys replacement principle =, that is, the sub-class has various attributes of the parent class, and the sub-class must implement all the methods of the parent class. Cannot be undone.
For example, if the parent class A has a non-virtual function method void F (), then subclass B inherits subclass A and overwrites F (); then a A = new B; then B. F () is to call the F () method in. If the F method is defined as virtual function. Then there is no such problem, because in this process, the compiler sees that the subclass inherits the parent class, and then uses dynamic binding when the new subclass is used. Then OK.
The first version of the Destructor is a virtual function, because the data in the object of the subclass is usually more than that in the parent class. So, if it is not a virtual function or a static binding, you can only delete the data part of the parent class. The memory space cannot be completely released.