The standard in section 12.8 / 7 states:
If the class definition does not explicitly declare a copy of the constructor, one is declared implicitly. If a class definition declares a move constructor or a move carry operator, an implicitly declared copy constructor is defined as deleted; otherwise, it is defined as default (8.4). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor. So for class definition
struct X { X(const X&, int); };
The copy constructor is implicitly declared. If a user-declared constructor is later defined as
X::X(const X& x, int i =0) { /∗ ... ∗/ }
I cannot understand that the latter case is out of date if the class has a user-declared copy destination operator or a user-declared destructor. In this example, the standard does not provide a custom copy assignment operator and destructor. What happens if we declare a destructor or copy assignment operator? I tried to do it as follows:
struct A { ~A(){ }; }; A::A(const A&){ };
Demo
but in this example, we still have an implicitly declared copy constructor. What does this rule mean?
I thought that if we write the following:
struct A { A(){ }; A(const A&&){ }; ~A(){ }; }; A a; A t = a;
Demo
the copy constructor will not be explicitly deleted. But it's not that.
user2953119
source share