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.


This is a new C++0x feature that tells the compiler to create the default version of the respective constructor or assignment operator, i.e. the one which just performs the copy or move action for each member. This is useful because the move constructor isn't always generated by default (e.g. if you have a custom destructor), unlike the copy constructor (and likewise for assignment), but if there's nothing non-trivial to write, it's better to let the compiler handle it than to spell it out yourself each time.

Also notice that a default constructor would not be generated if you provide any other non-default constructor. If you still want the default constructor, too, you can use this syntax to have the compiler make one.

As another use case, there are several situations in which a copy constructor would not be generated implicitly (e.g. if you provide a custom move constructor). If you still want the default version, you can request it with this syntax.

See Section 12.8 of the standard for details.


Another use case that I do not see mentioned in these answers is that it easily allows you to change the visibility of a constructor. For example, maybe you want a friend class to be able to access the copy constructor, but you don't want it to be publicly available.


It is new in C++11, see here. It can be quite useful if you have defined one constructor, but want to use defaults for the others. Pre-C++11 you'd have to define all constructors once you have defined one, even if they are equivalent to the defaults.

Also note that in certain situations it is impossible to provide a user defined default constructor that behaves the same as the compiler synthesized one under both default and value initialization. default allows you to get that behaviour back.