What does “default” mean after a class’ function declaration?

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 = 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.

Leave a Comment