Rule 3 Reject Member Default in C ++ 11

According to the well-known table below, automatic generation of the default copy constructor compiler and copy assignment is deprecated in C ++ 11 when one or more copy instances, copy constructor, and destructor are provided / provided by the user (red cells indicate fatigue). This makes sense in the light of Rule 3. However, the table shows that the default destructor generation is not out of date in the case of a user-created constructor / destination copy.

What is the rationale for this design decision?

Reference table

+4
source share
1 answer

? , , . :

template <class T>
class cloning_ptr
{
  std::unique_ptr<T> p;

public:
  cloning_ptr(const cloning_ptr &src) : p(std::make_unique<T>(*src.p) {}
  cloning_ptr(cloning_ptr &&) = default;

  cloning_ptr& operator= (cloning_ptr rhs)
  { swap(p, rhs.p); return *this; }    
};

, - .

: dtor, , , , . , , .

+2

Source: https://habr.com/ru/post/1678767/


All Articles