Special member functions in C++ are functions which the compiler will automatically generate if they are used, but not declared explicitly by the programmer. The automatically generated special member functions are:
Contents
In these cases the compiler generated versions of these functions perform a memberwise operation. For example the compiler generated destructor will destroy each sub-object (base class or member) of the object.
The compiler generated functions will be public
, non-virtual and the copy constructor and assignment operators will receive const&
parameters (and not be of the alternative legal forms).
Example
The following example depicts two classes: Explicit for which all C++98 special member functions are explicitly declared and Implicit for which none are declared.
Signatures
Here are the signatures of the special member functions:
C++98
In C++98 before the introduction of move semantics the special member functions were: