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:
“In England and America a beard usually means that its owner would rather be considered venerable than virile; on the continent of Europe it often means that its owner makes a special claim to virility.”
—Rebecca West (18921983)
“If there is among you anyone in need, a member of your community in any of your towns within the land that the LORD your God is giving you, do not be hard-hearted or tight-fisted toward your needy neighbor. You should rather open your hand, willingly lending enough to meet the need, whatever it may be.”
—Bible: Hebrew, Deuteronomy 15:7,8.
“Adolescents, for all their self-involvement, are emerging from the self-centeredness of childhood. Their perception of other people has more depth. They are better equipped at appreciating others reasons for action, or the basis of others emotions. But this maturity functions in a piecemeal fashion. They show more understanding of their friends, but not of their teachers.”
—Terri Apter (20th century)