- Source: Special member functions
In the C++ programming language, special member functions are functions which the compiler will automatically generate if they are used, but not declared explicitly by the programmer.
The automatically generated special member functions are:
Default constructor if no other constructor is explicitly declared.
Copy constructor if no move constructor and move assignment operator are explicitly declared.
If a destructor is declared generation of a copy constructor is deprecated (C++11, proposal N3242).
Move constructor if no copy constructor, copy assignment operator, move assignment operator and destructor are explicitly declared.
Copy assignment operator if no move constructor and move assignment operator are 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, move constructor and destructor are 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).
Example
The following example depicts two classes: Explicit for which all special member functions are explicitly declared and Implicit for which none are declared.
Signatures
Here are the signatures of the special member functions:
C++03
In C++03 before the introduction of move semantics (in C++11) the special member functions were:
Default constructor (if no other constructor is explicitly declared)
Copy constructor
Copy assignment operator
Destructor
References
Kata Kunci Pencarian:
- Daftar badan khusus Perserikatan Bangsa-Bangsa
- Sejarah Negara Palestina
- Mineral (nutrisi)
- M.I.A. (penyanyi rap)
- Arkea
- Frederick Brownell
- Nurhayati Ali Assegaf
- Special member functions
- C++11
- Assignment operator (C++)
- Special territories of members of the European Economic Area
- Method (computer programming)
- Signals and slots
- Rule of three (C++ programming)
- Special district (United States)
- Member state of the European Union
- Class variable