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:

    With a generous endowment of motherhood provided by legislation, with all laws against voluntary motherhood and education in its methods repealed, with the feminist ideal of education accepted in home and school, and with all special barriers removed in every field of human activity, there is no reason why woman should not become almost a human thing. It will be time enough then to consider whether she has a soul.
    Crystal Eastman (1881–1928)

    Luckless is the country in which the symbols of procreation are the objects of shame, while the agents of destruction are honored! And yet you call that member your pudendum, or shameful part, as if there were anything more glorious than creating life, or anything more atrocious than taking it away.
    Savinien Cyrano De Bergerac (1619–1655)

    If photography is allowed to stand in for art in some of its functions it will soon supplant or corrupt it completely thanks to the natural support it will find in the stupidity of the multitude. It must return to its real task, which is to be the servant of the sciences and the arts, but the very humble servant, like printing and shorthand which have neither created nor supplanted literature.
    Charles Baudelaire (1821–1867)