A function declaration introduces the function name and its type. It may appear in any scope, and is commonly placed in header files.
A function definition provides the body of a function. It may only appear in namespace or class scope.
attr(C++11)
|
-
|
Optional sequence of any number of function attributes, such as [[noreturn]] or [[carries_dependency]]. May appear both before and after the function name
|
ret
|
-
|
the type returned by the function, may be void if the function returns nothing. Cannot be array or function type, although can be a pointer or reference to such. Required for all functions except constructors, destructors, and conversion operators.
|
decl
|
-
|
declaration specifier sequence, which consists of none or some of the following keywords: static, extern, inline, virtual, explicit, friend, constexpr, combined with the return type, ret
|
cv
|
-
|
Optional const, volatile, or const volatile, only applicable to non-static member functions. For a member function of class T, the type of this will be const T*, volatile T*, or const volatile T* respectively. A member function declared const cannot modify members of *this.
|
ref(C++11)
|
-
|
Optional & or &&, only applicable to non-static member functions. For a member function of class T, the type of this will be T& or T&& respectively.
|
except
|
-
|
either dynamic-exception-specification or noexcept-specification
|
virt(C++11)
|
-
|
Optional override or final, only applicable to non-static member functions
|
->ret(C++11)
|
-
|
Trailing return type, only applicable if ret is auto. Useful if the type depends on argument names, such as template <class T, class U> auto add(T t, U u) -> decltype(t + u); or is complicated, such as in auto fpif(int)->int(*)(int)
|
init-list
|
-
|
Constructor initializer list, only used in constructors
|
try
|
-
|
Optional function try block. If present, catch must be provided
|
catch
|
-
|
Optional sequence of catch-blocks, only applicable of try is used.
|
body
|
-
|
The body of the function, a (possibly empty) compound statement
|
params
|
-
|
The list of parameters
|