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:
“Friendship is learned by watching and listening to you. If she sees that your friends are people you like and trust and dont pretend withpeople who suit youshe probably wont pick friends who just pass by, or people who can help her or improve her status. If you treat friends in a special way, if you are kinder, more generous, more sympathetic, more forgiving with friends, she probably will be, too.”
—Stella Chess (20th century)
“I wish to speak a word for Nature, for absolute freedom and wildness, as contrasted with a freedom and culture merely civil,to regard man as an inhabitant, or a part and parcel of Nature, rather than as a member of society. I wish to make an extreme statement, if so I may make an emphatic one, for there are enough champions of civilization: the minister and the school committee and every one of you will take care of that.”
—Henry David David (18171862)
“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 (18031882)