Стандарт C++ 98, страница 9
Описание файла
PDF-файл из архива "Стандарт C++ 98", который расположен в категории "". Всё это находится в предмете "практикум (прикладное программное обеспечение и системы программирования)" из 4 семестр, которые можно найти в файловом архиве МГУ им. Ломоносова. Не смотря на прямую связь этого архива с МГУ им. Ломоносова, его также можно найти и в других разделах. .
Просмотр PDF-файла онлайн
Текст 9 страницы из PDF
[Example:// translation unit 1:struct X {X(int);X(int, int);};X::X(int = 0) { }class D: public X { };D d2;// translation unit 2:struct X {X(int);X(int, int);};X::X(int = 0, int = 0) { }class D: public X { };// X(int) called by D()// X(int, int) called by D();// D()’s implicit definition// violates the ODR—end example] If D is a template, and is defined in more than one translation unit, then the last fourrequirements from the list above shall apply to names from the template’s enclosing scope used in thetemplate definition (14.6.3), and also to dependent names at the point of instantiation (14.6.2). If thedefinitions of D satisfy all these requirements, then the program shall behave as if there were a singledefinition of D.
If the definitions of D do not satisfy these requirements, then the behavior is undefined.3.3 Declarative regions and scopes1[basic.scope]Every name is introduced in some portion of program text called a declarative region, which is the largestpart of the program in which that name is valid, that is, in which that name may be used as an unqualifiedname to refer to the same entity. In general, each particular name is valid only within some possibly discontiguous portion of program text called its scope. To determine the scope of a declaration, it is sometimes convenient to refer to the potential scope of a declaration. The scope of a declaration is the same asits potential scope unless the potential scope contains another declaration of the same name. In that case,the potential scope of the declaration in the inner (contained) declarative region is excluded from the scopeof the declaration in the outer (containing) declarative region.__________________25) 8.3.6 describes how default argument names are looked up.24© ISO/IEC3 Basic concepts2ISO/IEC 14882:1998(E)3.3 Declarative regions and scopes[Example: inint j = 24;int main(){int i = j, j;j = 42;}the identifier j is declared twice as a name (and used twice).
The declarative region of the first j includesthe entire example. The potential scope of the first j begins immediately after that j and extends to the endof the program, but its (actual) scope excludes the text between the , and the }. The declarative region ofthe second declaration of j (the j immediately before the semicolon) includes all the text between { and },but its potential scope excludes the declaration of i. The scope of the second declaration of j is the sameas its potential scope. ]3The names declared by a declaration are introduced into the scope in which the declaration occurs, exceptthat the presence of a friend specifier (11.4), certain uses of the elaborated-type-specifier (3.3.1), andusing-directives (7.3.4) alter this general behavior.4Given a set of declarations in a single declarative region, each of which specifies the same unqualifiedname,— they shall all refer to the same entity, or all refer to functions and function templates; or— exactly one declaration shall declare a class name or enumeration name that is not a typedef name andthe other declarations shall all refer to the same object or enumerator, or all refer to functions and function templates; in this case the class name or enumeration name is hidden (3.3.7).
[Note: a namespacename or a class template name must be unique in its declarative region (7.3.2, clause 14). ][Note: these restrictions apply to the declarative region into which a name is introduced, which is not necessarily the same as the region in which the declaration occurs. In particular, elaborated-type-specifiers(3.3.1) and friend declarations (11.4) may introduce a (possibly not visible) name into an enclosing namespace; these restrictions apply to that region. Local extern declarations (3.5) may introduce a name into thedeclarative region where the declaration appears and also introduce a (possibly not visible) name into anenclosing namespace; these restrictions apply to both regions. ]5[Note: the name lookup rules are summarized in 3.4. ]3.3.1 Point of declaration1[basic.scope.pdecl]The point of declaration for a name is immediately after its complete declarator (clause 8) and before itsinitializer (if any), except as noted below. [Example:int x = 12;{ int x = x; }Here the second x is initialized with its own (indeterminate) value.
]2[Note: a nonlocal name remains visible up to the point of declaration of the local name that hides it.[Example:const int i = 2;{ int i[i]; }declares a local array of two integers. ] ]3The point of declaration for an enumerator is immediately after its enumerator-definition. [Example:const int x = 12;{ enum { x = x }; }Here, the enumerator x is initialized with the value of the constant x, namely 12.
]25ISO/IEC 14882:1998(E)© ISO/IEC3.3.1 Point of declaration43 Basic conceptsAfter the point of declaration of a class member, the member name can be looked up in the scope of itsclass. [Note: this is true even if the class is an incomplete class. For example,struct X {enum E { z = 16 };int b[X::z];};// OK—end note]5The point of declaration of a class first declared in an elaborated-type-specifier is as follows:— for an elaborated-type-specifier of the formclass-key identifier ;the elaborated-type-specifier declares the identifier to be a class-name in the scope that contains thedeclaration, otherwise— for an elaborated-type-specifier of the formclass-key identifierif the elaborated-type-specifier is used in the decl-specifier-seq or parameter-declaration-clause of afunction defined in namespace scope, the identifier is declared as a class-name in the namespace thatcontains the declaration; otherwise, except as a friend declaration, the identifier is declared in the smallest non-class, non-function-prototype scope that contains the declaration.
[Note: if the elaboratedtype-specifier designates an enumeration, the identifier must refer to an already declared enum-name. Ifthe identifier in the elaborated-type-specifier is a qualified-id, it must refer to an already declaredclass-name or enum-name. See 3.4.4. ]6[Note: friend declarations refer to functions or classes that are members of the nearest enclosing namespace,but they do not introduce new names into that namespace (7.3.1.2). Function declarations at block scopeand object declarations with the extern specifier at block scope refer to delarations that are members ofan enclosing namespace, but they do not introduce new names into that scope.
]7[Note: For point of instantiation of a template, see 14.7.1. ]3.3.2 Local scope[basic.scope.local]1A name declared in a block (6.3) is local to that block. Its potential scope begins at its point of declaration(3.3.1) and ends at the end of its declarative region.2The potential scope of a function parameter name in a function definition (8.4) begins at its point of declaration. If the function has a function try-block the potential scope of a parameter ends at the end of the lastassociated handler, else it ends at the end of the outermost block of the function definition. A parametername shall not be redeclared in the outermost block of the function definition nor in the outermost block ofany handler associated with a function try-block .3The name in a catch exception-declaration is local to the handler and shall not be redeclared in the outermost block of the handler.4Names declared in the for-init-statement, and in the condition of if, while, for, and switch statementsare local to the if, while, for, or switch statement (including the controlled statement), and shall notbe redeclared in a subsequent condition of that statement nor in the outermost block (or, for the if statement, any of the outermost blocks) of the controlled statement; see 6.4.3.3.3 Function prototype scope1[basic.scope.proto]In a function declaration, or in any function declarator except the declarator of a function definition (8.4),names of parameters (if supplied) have function prototype scope, which terminates at the end of the nearestenclosing function declarator.26© ISO/IECISO/IEC 14882:1998(E)3 Basic concepts3.3.4 Function scope3.3.4 Function scope1[basic.funscope]Labels (6.1) have function scope and may be used anywhere in the function in which they are declared.Only labels have function scope.3.3.5 Namespace scope1[basic.scope.namespace]The declarative region of a namespace-definition is its namespace-body.