Explicitly defaulted functions (C++11)
Explicitly defaulted function declaration is a new form of function declaration that is
introduced into the C++11 standard. You can append the =default; specifier to the
end of a function declaration to declare that function as an explicitly defaulted function. The
compiler generates the default implementations for explicitly defaulted functions, which are more
efficient than manually programmed function implementations. A function that is explicitly defaulted
must be a special member function and has no default arguments. Explicitly defaulted functions can
save your effort of defining those functions manually.
class A{
public:
A() = default; // Inline explicitly defaulted constructor definition
A(const A&);
~A() = default; // Inline explicitly defaulted destructor definition
};
A::A(const A&) = default; // Out-of-line explicitly defaulted constructor definition class B {
public:
int func() = default; // Error, func is not a special member function.
B(int, int) = default; // Error, constructor B(int, int) is not
// a special member function.
B(int=0) = default; // Error, constructor B(int=0) has a default argument.
};
The explicitly defaulted function declarations enable more opportunities in optimization, because the compiler might treat explicitly defaulted functions as trivial.