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:
“When, in some obscure country town, the farmers come together to a special town meeting, to express their opinion on some subject which is vexing to the land, that, I think, is the true Congress, and the most respectable one that is ever assembled in the United States.”
—Henry David Thoreau (18171862)
“There are several natural phenomena which I shall have to have explained to me before I can keep on going as a resident member of the human race. One is the metamorphosis which hats and suits undergo exactly one week after their purchase, whereby they are changed from smart, intensely becoming articles of apparel into something children use when they want to dress up like daddy.”
—Robert Benchley (18891945)
“One of the most highly valued functions of used parents these days is to be the villains of their childrens lives, the people the child blames for any shortcomings or disappointments. But if your identity comes from your parents failings, then you remain forever a member of the child generation, stuck and unable to move on to an adulthood in which you identify yourself in terms of what you do, not what has been done to you.”
—Frank Pittman (20th century)