[special] (original) (raw)

11 Classes [class]

11.4 Class members [class.mem]

11.4.4 Special member functions [special]

[Note 1:

The implementation will implicitly declare these member functions for some class types when the program does not explicitly declare them.

— _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.

[Example 1:

A program may explicitly call or form a pointer to member to an implicitly-declared special member function.

struct A { }; struct B : A { B& operator=(const B &);}; B& B::operator=(const B& s) { this->A::operator=(s); return *this;} — _end example_]

[Note 2:

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]).

[Example 2:

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

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.