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:

    “People generally will soon understand that writers should be judged, not according to rules and species, which are contrary to nature and art, but according to the immutable principles of the art of composition, and the special laws of their individual temperaments.”
    —Victor Hugo (1802–1885)

    “Before I knew that I was Jewish or a girl I knew that I was a member of the working class. At a time when I had not yet grasped the significance of the fact that in my house English was a second language, or that I wore dresses while my brother wore pants, I knew—and I knew it was important to know—that Papa worked hard all day long.”
    —Vivian Gornick (b. 1935)

    “The mind is a finer body, and resumes its functions of feeding, digesting, absorbing, excluding, and generating, in a new and ethereal element. Here, in the brain, is all the process of alimentation repeated, in the acquiring, comparing, digesting, and assimilating of experience. Here again is the mystery of generation repeated.”
    —Ralph Waldo Emerson (1803–1882)