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:
“The very best reason parents are so special . . . is because we are the holders of a priceless gift, a gift we received from countless generations we never knew, a gift that only we now possess and only we can give to our children. That unique gift, of course, is the gift of ourselves. Whatever we can do to give that gift, and to help others receive it, is worth the challenge of all our human endeavor.”
—Fred Rogers (20th century)
“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.
“Nobody is so constituted as to be able to live everywhere and anywhere; and he who has great duties to perform, which lay claim to all his strength, has, in this respect, a very limited choice. The influence of climate upon the bodily functions ... extends so far, that a blunder in the choice of locality and climate is able not only to alienate a man from his actual duty, but also to withhold it from him altogether, so that he never even comes face to face with it.”
—Friedrich Nietzsche (18441900)