I’ve seen default used next to function declarations in a class. What does it do?
class C {
C(const C&) = default;
C(C&&) = default;
C& operator=(const C&) & = default;
C& operator=(C&&) & = default;
virtual ~C() { }
};
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a new C++11 feature.
It means that you want to use the compiler-generated version of that function, so you don’t need to specify a body.
You can also use
= deleteto specify that you don’t want the compiler to generate that function automatically.With the introduction of move constructors and move assignment operators, the rules for when automatic versions of constructors, destructors and assignment operators are generated has become quite complex. Using
= defaultand= deletemakes things easier as you don’t need to remember the rules: you just say what you want to happen.