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:

    An indirect quotation we can usually expect to rate only as better or worse, more or less faithful, and we cannot even hope for a strict standard of more and less; what is involved is evaluation, relative to special purposes, of an essentially dramatic act.
    Willard Van Orman Quine (b. 1908)

    We live in a highly industrialized society and every member of the Black nation must be as academically and technologically developed as possible. To wage a revolution, we need competent teachers, doctors, nurses, electronics experts, chemists, biologists, physicists, political scientists, and so on and so forth. Black women sitting at home reading bedtime stories to their children are just not going to make it.
    Frances Beale, African American feminist and civil rights activist. The Black Woman, ch. 14 (1970)

    Empirical science is apt to cloud the sight, and, by the very knowledge of functions and processes, to bereave the student of the manly contemplation of the whole.
    Ralph Waldo Emerson (1803–1882)