Movatterモバイル変換


[0]ホーム

URL:


9 Declarations[dcl]

9.6 Function definitions[dcl.fct.def]

9.6.1 General[dcl.fct.def.general]

Any informal reference to the body of a function should be interpreted as a reference tothe non-terminalfunction-body,including, for a constructor,default member initializers or default initializationused to initializea base or member subobject in the absence ofamem-initializer-id ([class.base.init]).
The optionalattribute-specifier-seq in afunction-definitionappertains to the function.
Afunction-definition with arequires-clauseshall define a templated function.
In afunction-definition,eithervoiddeclarator;ordeclarator;shall be a well-formed function declarationas described in[dcl.fct].
A function shall be defined only in namespace or class scope.
The type of a parameter or the return type for a functiondefinition shall not bea (possibly cv-qualified) class type that isincomplete or abstract within the function bodyunless the function is deleted ([dcl.fct.def.delete]).
[Example 1: 
A simple example of a complete function definition isint max(int a,int b,int c){int m=(a> b)? a: b;return(m> c)? m: c;}
Hereintis thedecl-specifier-seq;max(inta,intb,intc)is thedeclarator;{/* ... */}is thefunction-body.
— end example]
Actor-initializeris used only in a constructor; see[class.ctor] and[class.init].
[Note 1: 
Acv-qualifier-seq affects the type ofthisin the body of a member function; see[expr.prim.this].
— end note]
[Note 2: 
Unused parameters need not be named.
For example,
void print(int a,int){ std::printf("a = %d\n",a);} — end note]
Afunction-local predefined variable is a variable with staticstorage duration that is implicitly defined in a function parameter scope.
The function-local predefined variable__func__ isdefined as if a definition of the formstaticconstchar __func__[]="function-name";had been provided, wherefunction-name is animplementation-defined string.
It is unspecified whether such a variable has an addressdistinct from that of any other object in the program.76
[Example 2: struct S{ S(): s(__func__){}// OKconstchar* s;};void f(constchar* s= __func__);// error:__func__ is undeclared — end example]
76)76)
Implementations arepermitted to provide additional predefined variables with names that are reserved to theimplementation ([lex.name]).
If a predefined variable is notodr-used ([basic.def.odr]), its string value need not be present in the program image.

[8]ページ先頭

©2009-2026 Movatter.jp