cpp/language/functions

Functions are C++ entities that associate a sequence of (a function body) with a name and a list of zero or more function parameters.

When a function is invoked, e.g. in a, the parameters are initialized from the arguments (either provided at the place of call or ) and the statements in the function body are executed. If the ends with, extra arguments can be supplied to the function, such a function is called.

function names in function-call expressions are looked up with an extra set of rules called.

A function can terminate by or by  an.

A may appear in any scope, but a  may only appear in namespace scope or, for  and  functions, in class scope. A function that is declared in a class body without a friend specifier is a class member function. Such functions have many additional properties, see for details.

Functions are not objects: there are no arrays of functions and functions cannot be passed by value or returned from other functions. Pointers and references to functions (except for ) are allowed, and may be used where these functions themselves cannot. Therefore we say these functions are "addressable".

Each function has a type, which consists of the function's return type, the types of all parameters (after array-to-pointer and function-to-pointer transformations, see ), and, for non-static member functions, cv-qualification. Function types also have. There are no cv-qualified function types (not to be confused with the types of such as  or functions returning, such as ). Any cv-qualifier is ignored if it is added to an alias for a function type.

Multiple functions in the same scope may have the same name, as long as their parameter lists and, for non-static member functions, cv-qualifications are different. This is known as. Function declarations that differ only in the return type cannot be overloaded. The is determined differently.

Function objects
Besides function lvalues, the function call expression supports pointers to functions, and any value of class type that overloads the function-call operator or is convertible to function pointer. Together, these types are known as s, and they are used ubiquitously through the C++ standard library, see for example, usages of and.

The standard library also provides a number of pre-defined function object templates as well as the methods to compose new ones (including std).