Стандарт C++ 98 (1119566), страница 11
Текст из файла (страница 11)
][Note: 3.3.6 further describes the restrictions on the use of names in a class definition. 9.7 further describesthe restrictions on the use of names in nested class definitions. 9.8 further describes the restrictions on theuse of names in local class definitions. ]8A name used in the definition of a function that is a member function (9.3)29) of class X shall be declared inone of the following ways:— before its use in the block in which it is used or in an enclosing block (6.3), or— shall be a member of class X or be a member of a base class of X (10.2), or— if X is a nested class of class Y (9.7), shall be a member of Y, or shall be a member of a base class of Y(this lookup applies in turn to Y’s enclosing classes, starting with the innermost enclosing class),30) or— if X is a local class (9.8) or is a nested class of a local class, before the definition of class X in a blockenclosing the definition of class X, or— if X is a member of namespace N, or is a nested class of a class that is a member of N, or is a local classor a nested class within a local class of a function that is a member of N, before the member functiondefinition, in namespace N or in one of N’s enclosing namespaces.[Example:class B { };namespace M {namespace N {class X : public B {void f();};}}void M::N::X::f() {i = 16;}__________________29) That is, an unqualified name following the function declarator; such a name may be used as a type or as a default argument name inthe parameter-declaration-clause, or may be used in the function body, or, if the function is a constructor, may be used in the expression of a mem-initializer.30) This lookup applies whether the member function is defined within the definition of class X or whether the member function isdefined in a namespace scope enclosing X’s definition.31ISO/IEC 14882:1998(E)© ISO/IEC3.4.1 Unqualified name lookup3 Basic concepts// The following scopes are searched for a declaration of i:// 1) outermost block scope of M::N::X::f, before the use of i// 2) scope of class M::N::X// 3) scope of M::N::X’s base class B// 4) scope of namespace M::N// 5) scope of namespace M// 6) global scope, before the definition of M::N::X::f—end example] [Note: 9.3 and 9.4 further describe the restrictions on the use of names in member functiondefinitions.
9.7 further describes the restrictions on the use of names in the scope of nested classes. 9.8 further describes the restrictions on the use of names in local class definitions. ]9Name lookup for a name used in the definition of a friend function (11.4) defined inline in the classgranting friendship shall proceed as described for lookup in member function definitions. If the friendfunction is not defined in the class granting friendship, name lookup in the friend function definitionshall proceed as described for lookup in namespace member function definitions.10In a friend declaration naming a member function, a name used in the function declarator and not part ofa template-argument in a template-id is first looked up in the scope of the member function’s class. If it isnot found, or if the name is part of a template-argument in a template-id, the look up is as described forunqualified names in the definition of the class granting friendship.
[Example:struct A {typedef int AT;void f1(AT);void f2(float);};struct B {typedef float BT;friend void A::f1(AT);friend void A::f2(BT);};// parameter type is A::AT// parameter type is B::BT—end example]11During the lookup for a name used as a default argument (8.3.6) in a function parameter-declaration-clauseor used in the expression of a mem-initializer for a constructor (12.6.2), the function parameter names arevisible and hide the names of entities declared in the block, class or namespace scopes containing the function declaration. [Note: 8.3.6 further describes the restrictions on the use of names in default arguments.12.6.2 further describes the restrictions on the use of names in a ctor-initializer.
]12A name used in the definition of a static data member of class X (9.4.2) (after the qualified-id of thestatic member) is looked up as if the name was used in a member function of X. [Note: 9.4.2 furtherdescribes the restrictions on the use of names in the definition of a static data member. ]13A name used in the handler for a function-try-block (clause 15) is looked up as if the name was used in theoutermost block of the function definition.
In particular, the function parameter names shall not be redeclared in the exception-declaration nor in the outermost block of a handler for the function-try-block.Names declared in the outermost block of the function definition are not found when looked up in the scopeof a handler for the function-try-block. [Note: but function parameter names are found. ]14[Note: the rules for name lookup in template definitions are described in 14.6.
]3.4.2 Argument-dependent name lookup1[basic.lookup.koenig]When an unqualified name is used as the postfix-expression in a function call (5.2.2), other namespaces notconsidered during the usual unqualified lookup (3.4.1) may be searched, and namespace-scope friend function declarations (11.4) not otherwise visible may be found. These modifications to the search depend onthe types of the arguments (and for template template arguments, the namespace of the template argument).32© ISO/IECISO/IEC 14882:1998(E)3 Basic concepts23.4.2 Argument-dependent name lookupFor each argument type T in the function call, there is a set of zero or more associated namespaces and a setof zero or more associated classes to be considered. The sets of namespaces and classes is determinedentirely by the types of the function arguments (and the namespace of any template template argument).Typedef names and using-declarations used to specify the types do not contribute to this set.
The sets ofnamespaces and classes are determined in the following way:— If T is a fundamental type, its associated sets of namespaces and classes are both empty.— If T is a class type, its associated classes are the class itself and its direct and indirect base classes. Itsassociated namespaces are the namespaces in which its associated classes are defined.— If T is a union or enumeration type, its associated namespace is the namespace in which it is defined.
Ifit is a class member, its associated class is the member’s class; else it has no associated class.— If T is a pointer to U or an array of U, its associated namespaces and classes are those associated with U.— If T is a function type, its associated namespaces and classes are those associated with the functionparameter types and those associated with the return type.— If T is a pointer to a member function of a class X, its associated namespaces and classes are those associated with the function parameter types and return type, together with those associated with X.— If T is a pointer to a data member of class X, its associated namespaces and classes are those associatedwith the member type together with those associated with X.— If T is a template-id, its associated namespaces and classes are the namespace in which the template isdefined; for member templates, the member template’s class; the namespaces and classes associatedwith the types of the template arguments provided for template type parameters (excluding templatetemplate parameters); the namespaces in which any template template arguments are defined; and theclasses in which any member templates used as template template arguments are defined.
[Note: nontype template arguments do not contribute to the set of associated namespaces. ]If the ordinary unqualified lookup of the name finds the declaration of a class member function, the associated namespaces and classes are not considered. Otherwise the set of declarations found by the lookup ofthe function name is the union of the set of declarations found using ordinary unqualified lookup and the setof declarations found in the namespaces and classes associated with the argument types.
[Example:namespace NS {class T { };void f(T);}NS::T parm;int main() {f(parm);}// OK: calls NS::f—end example]3When considering an associated namespace, the lookup is the same as the lookup performed when the associated namespace is used as a qualifier (3.4.3.2) except that:— Any using-directives in the associated namespace are ignored.— Any namespace-scope friend functions declared in associated classes are visible within their respectivenamespaces even if they are not visible during an ordinary lookup (11.4).3.4.3 Qualified name lookup1[basic.lookup.qual]The name of a class or namespace member can be referred to after the :: scope resolution operator (5.1)applied to a nested-name-specifier that nominates its class or namespace. During the lookup for a namepreceding the :: scope resolution operator, object, function, and enumerator names are ignored.
If thename found is not a class-name (clause 9) or namespace-name (7.3.1), the program is ill-formed. [Example:33ISO/IEC 14882:1998(E)© ISO/IEC3.4.3 Qualified name lookupclass A {public:static int n;};int main(){int A;A::n = 42;A b;}3 Basic concepts// OK// ill-formed: A does not name a type—end example]2[Note: Multiply qualified names, such as N1::N2::N3::n, can be used to refer to members of nestedclasses (9.7) or members of nested namespaces.
]3In a declaration in which the declarator-id is a qualified-id, names used before the qualified-id beingdeclared are looked up in the defining namespace scope; names following the qualified-id are looked up inthe scope of the member’s class or namespace. [Example:class X { };class C {class X { };static const int number = 50;static X arr[number];};X C::arr[number];// ill-formed:// equivalent to: ::X C::arr[C::number];// not to: C::X C::arr[C::number];—end example]4A name prefixed by the unary scope operator :: (5.1) is looked up in global scope, in the translation unitwhere it is used.