I know that when I define an empty class and provide no declarations at all, the compiler will provide definitions for the default and copy constructor, destructor and copy assignment operator.
What are the rules for that? When does the compiler not provide a, say, copy constructor? What about the move constructor and move assignment operator?
(Example: The compiler will not provide definitions for any assignment operator if my class has a reference member like int&
. When else will something like this happen?)
Edit: In C++11 it's more complicated than implicitly declared or not. They can either be implicitly declared and defaulted, implicitly declared and deleted, or undeclared. Read this to distinguish the latter 2. The following information isn't entirely correct since it doesn't distinguish declared and deleted vs undeclared.
The following is a work in progress.
(?)
indicates I would like to clarify or quantify the statement.Special Member Functions §12/1
The implementation will implicitly declare these member functions for some class types when the user does not explicitly declare them:
A special member function will NOT be implicitly declared if the type has a...
Default Constructor §12.1/5
Copy Constructor §12.8/8, §12.8/12
*Such an implicit declaration is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor (?)
Copy Assignment Operator §12.8/19, §12.8/24
*Such implicit declaration is deprecated if the class has a user-declared copy constructor or a user-declared destructor (?)
Move Constructor §12.8/10, §12.8/12
Move Assignment Operator §12.8/21, §12.8/24
Destructor §12.4/4