current position:Home>Why does the subclass object report an error when calling the virtual destructor after the object of the base class calls the virtual destructor? It's no problem if the base class doesn't call it. Why do two different objects affect each other?

Why does the subclass object report an error when calling the virtual destructor after the object of the base class calls the virtual destructor? It's no problem if the base class doesn't call it. Why do two different objects affect each other?

2022-01-27 00:59:18 CSDN Q & A

I created the base class A, There are two virtual functions written in it show() and ~A()
Created subclasses B. Wrote a member function fun()
Two objects are created in the main function a1 and b1, Call the virtual function on these two objects through the virtual function table
When calling the a1 The second function of ( That is, the virtual destructor ) after b1 Easy to use makes mistakes , Segment error . Run normally without calling .




Refer to the answer 1:

Can you post the code




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270059168343.html

Random recommended