Possible reasons why destructors were not executed when C + + DELETE

Source: Internet
Author: User

In the delete location, there is no corresponding header file, but only the class's predecessor declaration;

Perhaps the delete is a base class pointer, and the compiler knows the base class, so there is no subclass # include;

If you want to release the memory of the base class when you delete the subclass object, be sure to write the base class destructor as virtual;

If a class does not contain virtual functions, it generally means that it will not be used as a base class. When a class is not intended to be used as a base class, do not define a virtual destructor because it adds a virtual function table, doubling the volume of the object, and possibly reducing its possible value.

So the basic one is: declaring a virtual destructor without reason is as wrong as never declaring it.

Declare a virtual destructor when and only if the class contains at least one virtual function.

Possible reasons why destructors were not executed when C + + DELETE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.