Effective C + +--tectonic-destructor assignment operation

Source: Internet
Author: User
05. Understand what functions C + + silently writes and calls
  • Compile the resulting destructor when non-virtual, unless the base class destructor for this class is virtual
  • Copy assignment function cannot be generated automatically when there are references and const members in member variables
  • When the base class declares the copy assignment operator as private, the compiler refuses to generate a copy assignment operator for its derived classes.
06. If you do not want to use a function generated automatically by the compiler, you should explicitly deny
  • Automatically generated default constructor, copy constructor, copy assignment declared as private
  • Declaring private is not completely secure, and member functions and friend functions can be called--and declared, but not defined (resulting in link errors)
  • Define a base class, default constructor, copy constructor, copy assignment declared as private, inherit from derived class (Generate compilation error, Noncopyable class in Boost)
07. Declaring the virtual destructor for a polymorphic base class
  • When a base class pointer points to a derived class, the Delete base class pointer cannot be called to the destructor of the derived class
  • Any class with the virtual function should have a virtual destructor.
  • When class does not contain a virtual function, it usually means that it is not intended to be used as a base class.
  • When class does not attempt to be treated as a base class, its destructor is often a bad idea for virtual. (Occupy space, reduce efficiency)
08. Don't let exceptions escape destructors
  • When a destructor does not catch an exception, if the class object is stored in a container, an exception may cause other objects in the container to be unable to refactor.
  • Destructors need to catch exceptions, some actions that throw exceptions can be moved out of the destructor and processed by a customer call




Effective C + +--tectonic-destructor assignment operation

Related Article

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.