Special Member Functions

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 special member functions are:

  • Default constructor (if no other constructor is explicitly declared)
  • Copy constructor if no move constructor or move assignment operator is explicitly declared.
If a destructor is declared generation of a copy constructor is deprecated.
  • Move constructor if no copy constructor, move assignment operator or destructor is explicitly declared.
  • Copy assignment operator if no move constructor or move assignment operator is explicitly declared.
If a destructor is declared generation of a copy assignment operator is deprecated.
  • Move assignment operator if no copy constructor, copy assignment operator or destructor is explicitly declared.
  • Destructor

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

Read more about Special Member Functions:  Example, Signatures, C++98

Famous quotes containing the words special, member and/or functions:

    The universal social pressure upon women to be all alike, and do all the same things, and to be content with identical restrictions, has resulted not only in terrible suffering in the lives of exceptional women, but also in the loss of unmeasured feminine values in special gifts. The Drama of the Woman of Genius has too often been a tragedy of misshapen and perverted power.
    Anna Garlin Spencer (1851–1931)

    Neighboring farmers and visitors at White Sulphur drove out occasionally to watch ‘those funny Scotchmen’ with amused superiority; when one member imported clubs from Scotland, they were held for three weeks by customs officials who could not believe that any game could be played with ‘such elongated blackjacks or implements of murder.’
    —For the State of West Virginia, U.S. public relief program (1935-1943)

    Those things which now most engage the attention of men, as politics and the daily routine, are, it is true, vital functions of human society, but should be unconsciously performed, like the corresponding functions of the physical body.
    Henry David Thoreau (1817–1862)