First assume that you know the role of virtual functions. .
Every time you call the constructor, you and the compiler will clearly know the data type to be constructed, and then the base class constructor will be called again in the constructor
When calling the destructor, if the current pointer is a base class pointer, then you and the compiler will not be able to tell whether the space pointed by the pointer is a base class object or a derived class. At this time, the runtime needs to Check in the virtual function table which destructor needs to be called
I don’t want to write anymore, I’ll find two posts for you
First assume that you know the role of virtual functions. .
Every time you call the constructor, you and the compiler will clearly know the data type to be constructed, and then the base class constructor will be called again in the constructor
When calling the destructor, if the current pointer is a base class pointer, then you and the compiler will not be able to tell whether the space pointed by the pointer is a base class object or a derived class. At this time, the runtime needs to Check in the virtual function table which destructor needs to be called