patterncppCritical
What does "default" mean after a class' function declaration?
Viewed 0 times
declarationfunctionclassdoesmeanafterwhatdefault
Problem
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() { }
};Solution
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
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
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
= delete to 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
= default and = delete makes things easier as you don't need to remember the rules: you just say what you want to happen.Context
Stack Overflow Q#6502828, score: 358
Revisions (0)
No revisions yet.