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 experience and behaviour that gets labelled schizophrenic is a special strategy that a person invents in order to live in an unlivable situation.”
—R.D. (Ronald David)
“When Hitler attacked the Jews ... I was not a Jew, therefore, I was not concerned. And when Hitler attacked the Catholics, I was not a Catholic, and therefore, I was not concerned. And when Hitler attacked the unions and the industrialists, I was not a member of the unions and I was not concerned. Then, Hitler attacked me and the Protestant churchand there was nobody left to be concerned.”
—Martin Niemller (18921984)
“The English masses are lovable: they are kind, decent, tolerant, practical and not stupid. The tragedy is that there are too many of them, and that they are aimless, having outgrown the servile functions for which they were encouraged to multiply. One day these huge crowds will have to seize power because there will be nothing else for them to do, and yet they neither demand power nor are ready to make use of it; they will learn only to be bored in a new way.”
—Cyril Connolly (19031974)