Always remember to declare the Destructor as virtual ----> < >
Maybe you don't think this sentence is correct, but you don't need to question it.
View the following example:
# Include
# Include
Using namespace std; class B {public :~ B () {cout <"base is destroyed! "<
This is a simple example, and the output is positive.
However, let's look at the test below!
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink">
VcD4KPHA + PHByZSBjbGFzcz0 = "brush: java;"> # include
# Include
Using namespace std; class B {public :~ B () {cout <"base is destroyed! "<
Therefore, when a base class Pointer Points to an object in a derived class and deletes the pointer directly, the Destructor call chain will be damaged.
# Include
# Include
Using namespace std; class B {public: virtual ~ B () {cout <"base is destroyed! "<
Therefore, remember to declare the Destructor as virtual, so you never have to worry about the destruction of the Destructor call chain!