cpp/language/default arguments

Allows a function to be called without providing one or more trailing arguments.

Indicated by using the following syntax for a parameter in the of a.

Default arguments are used in place of the missing trailing arguments in a function call:

In a function declaration, after a parameter with a default argument, all subsequent parameters must:
 * have a default argument supplied in this or a previous declaration from the same scope:

The ellipsis is not a parameter, and so can follow a parameter with a default argument:

Default arguments are only allowed in the parameter lists of and are not allowed in the declarations of pointers to functions, references to functions, or in  declarations. Template parameter lists use similar syntax for their.

For non-template functions, default arguments can be added to a function that was already declared if the function is redeclared in the same scope. At the point of a function call, the defaults are a union of the defaults provided in all visible declarations for the function. A redeclaration cannot introduce a default for an argument for which a default is already visible (even if the value is the same). A re-declaration in an inner scope does not acquire the default arguments from outer scopes.

If an function is declared in different translation units, the accumulated sets of default arguments must be the same at the end of each translation unit.

If a declaration specifies a default, it must be a friend function definition, and no other declarations of this function are allowed in the translation unit.

The carries over the set of known default arguments, and if more arguments are added later to the function's namespace, those defaults are also visible anywhere the using-declaration is visible:

The names used in the default arguments are looked up, checked for, and bound at the point of declaration, but are executed at the point of the function call:

For a of a non-template class, the default arguments are allowed on the out-of-class definition, and are combined with the default arguments provided by the declaration inside the class body. If these out-of-class defaults would turn a member function into a default constructor or copy constructor/assignment operator, the program is ill-formed. For member functions of class templates, all defaults must be provided in the initial declaration of the member function.

The overriders of functions do not acquire the default arguments from the base class declarations, and when the virtual function call is made, the default arguments are decided based on the static type of the object (note: this can be avoided with non-virtual interface pattern).

Local variables are not allowed in default arguments unless they are :

The pointer is not allowed in default arguments:

Non-static class members are not allowed in default arguments (even if they are not evaluated), except when used to form a pointer-to-member or in a member access expression:

A default argument is evaluated each time the function is called with no argument for the corresponding parameter. Function parameters are not allowed in default arguments except if they are. Note that parameters that appear earlier in the parameter list are in :

The default arguments are not part of the function type:

Operator functions cannot have default arguments, except for the function call operator:

Note
Spaces may be necessary to avoid a compound assignment token if the parameter name is absent.