11 Classes [class]

11.4 Class members [class.mem]

11.4.3 Special member functions [special]

Default constructors ([class.default.ctor]), copy constructors, move constructors ([class.copy.ctor]), copy assignment operators, move assignment operators ([class.copy.assign]), and prospective destructors ([class.dtor]) are special member functions.
The implementation will implicitly declare these member functions for some class types when the program does not explicitly declare them.
The implementation will implicitly define them if they are odr-used ([basic.def.odr]) or needed for constant evaluation ([expr.const]).
— end note]
An implicitly-declared special member function is declared at the closing } of the class-specifier.
Programs shall not define implicitly-declared special member functions.
Programs may explicitly refer to implicitly-declared special member functions.
A program may explicitly call or form a pointer to member to an implicitly-declared special member function.
struct A { };                   // implicitly declared A​::​operator=
struct B : A {
  B& operator=(const B &);
B& B::operator=(const B& s) {
  this->A::operator=(s);        // well-formed
  return *this;
— end example]
The special member functions affect the way objects of class type are created, copied, moved, and destroyed, and how values can be converted to values of other types.
Often such special member functions are called implicitly.
— end note]
Special member functions obey the usual access rules ([class.access]).
Declaring a constructor protected ensures that only derived classes and friends can create objects using it.
— end example]
Two special member functions are of the same kind if:
  • they are both default constructors,
  • they are both copy or move constructors with the same first parameter type, or
  • they are both copy or move assignment operators with the same first parameter type and the same cv-qualifiers and ref-qualifier, if any.
An eligible special member function is a special member function for which:
For a class, its non-static data members, its non-virtual direct base classes, and, if the class is not abstract ([class.abstract]), its virtual base classes are called its potentially constructed subobjects.
A defaulted special member function is constexpr-compatible if the corresponding implicitly-declared special member function would be a constexpr function.