C++ Non-Abstract Destructor Inheritance -
I have asked this before, but not clearly, or as I have found, in the same situation.
I have the essence class, it is a protected manufacturer and a destroyer. It has been inherited in many ways, including public constructors and destructors. I am having trouble where children are not called to call the Destructors if the object is removed if the object is referred to as a base type.
class Tree {protected: Tree () {} public: ~ tree () {}}; Square Oak Tree: Public Tree {Public: Oak Tree () {} ~ Oak Tree () {}}; Of vector & lt; Tree * & gt; Tree; // store objects base type paste present_back (new octroi ()); // Create derived objects tree [0]; // Oak Tree Discoctor is not called How can I call Oak Tree District? I have tried to mark all the destructors as virtual but it is not working. Base class destructor can not be abstract (this calling will solve the problem, but not the problem of the delay).
Make your base-class destructor the virtual .
class tree {protected: tree} () {} public: virtual ~ tree () {}} Otherwise, the result of undefined behavior would be You try to remove it through base-class pointers. This is a bit of date, but Scott Meyers has expressed colorful in effective C ++ , 2G version:
: C ++ Language Standards The topic is unusually clear: When you try to remove a derived class object through base class pointers and the nonvirtual destructor in the base class (as
EnemyTarget), The results are undefined. This means that the compiler can generate code to do whatever it wants: reformat your disk, send an indicator mail to your boss, send fax source code to your competitors, whatever (in runtime often What happens is that the derivative class district code is never called ... ...)
Comments
Post a Comment