3.3 - [Basic.scope] - [Basic. Scope]

xiaoxiao2021-03-06  111

Please don't reprint this article; please don't re-publish this article in any form; please delete it within 24 hours of downloading this article; it is forbidden to use this article for commercial purposes.

3 Basic Concepts [Basic] 3.3 Declarative Regions and scopes [Basic.Scope] 3 Basic Concepts [Basic] 3.3 Declaration Areas and Scope [Basic. Scope] Every Name Is Introduces IN Some Portion of Program Text Called A Declarative Region, Which is the largest part of the program in which that name is valid, that is, in which that name may be used as an unqualified name 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 as its potential scope unless the potential scope contains another declaration of the same program text name. in that case, the potential scope of the declaration in the inner (contained) declarative region is excluded from the scope of the declaration in (containing) declarative region the outer. each name is introduced into some of the In some parts of the declaration area, the declaration area is the broadest region that is valid in the program, that is, this name can be used as a non-qualified name and refer to The same entity. Typically, each particular name is only valid in discontinuous regions known in the program as the name of the name. To determine a scope of a statement, it is usually convenient to mention the potential scope of the declaration. The scope of the declaration is the same as its potential scope, unless there is another statement of the same name. At this time, the potential scope declared in the internal (included) declaration area is excluded by the scope declared in the outside (included) declaration area.

[EXAMPLE: INT J = 24; int main () {INT i = J, J; J = 42;} The Identifier J Is Declared TWICE A Name (and used twice). The Decludes The first j incover entire example. The potential scope of the first j begins immediately after that j and extends to the end of the program, but its (actual) scope excludes the text between the, and the}. The declarative region of the 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 same as its potential scope] [Example: below int j = 24; int Main () {INT i = J, J; J = 42;} The identifier J is declared twice (and applied twice). The declaration area of ​​the first J includes the entire program. The potential scope of the first J starts from J's statement, and expands to the end of the program, but its (actual) scope excludes text from, to}. The second J declaration (next to the semicoloned J) declaration area includes all text from {to}, but its potential scope does not include the declaration of I. The scope of the second J is the same as its potential scope. ] The names declared by a declaration are introduced into the scope in which the declaration occurs, except that the presence of a friend specifier (11.4), certain uses of the elaborated-type-specifier (3.3.1), and using-directives ( 7.3.4) Alter this general behavior. Declare that the name is introduced into the scope of the declaration, unless the declaration has a specific usage of the Friend Limit (11.4), including the detailed type limiting (3.3.1), or uses instructions (7.3. 4) Change its general behavior. Given a set of declarations in a Single Declarative Region, Each of Which Specifies the Same Unqualified Name,

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 and the 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 namespace name 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 the declarative region where the declaration appears and also introduce a (po SSIBLY NOT Visible) Name Into An Enclosing Namespace; The Restrictions Apply to Both Regions.] If a set of non-qualified names are specified in a single declaration area,

转载请注明原文地址:https://www.9cbs.com/read-97351.html

New Post(0)