Namespaces
Variants
Actions

Function declaration

From cppreference.com
< cpp‎ | language
 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 
 

A function declaration introduces the function name and its type. A function definition associates the function name/type with the function body.

Contents

[edit] Function declaration

Function declarations may appear in any scope. A function declaration at class scope introduces a class member function (unless the friend specifier is used), see member functions and friend functions for details.

noptr-declarator ( parameter-list ) cv (optional) ref  (optional) except (optional) attr (optional) (1)
noptr-declarator ( parameter-list ) cv (optional) ref  (optional) except (optional) attr (optional)
-> trailing
(2) (since C++11)

(see Declarations for the other forms of the declarator syntax)

1) Regular function declarator syntax.
2) Trailing return type declaration. The decl-specifier-seq in this case must contain the keyword auto.
noptr-declarator - any valid declarator, but if it begins with *, &, or &&, it has to be surrounded by parentheses.
parameter-list - possibly empty, comma-separated list of the function parameters (see below for details)
attr - (since C++11) a list of attributes. These attributes are applied to the type of the function, not the function itself. The attributes for the function appear after the identifier within the declarator and are combined with the attributes that appear in the beginning of the declaration, if any.
cv - const/volatile qualification, only allowed in non-static member function declarations
ref - (since C++11) ref-qualification, only allowed in non-static member function declarations
except -