|
From: Barry on 26 Jan 2008 02:24 wasosa(a)sbcglobal.net wrote: > Consider the following code: > > class A > { > friend class B& foo(class B&, A&); > }; > > Now consider the slightly different > > class A > { > friend class B& foo(B&, A&); > }; > > My question is, are both of these valid c++ code? > Specifically, do we still need to specify 'class B&' in the parameter > list? > <std> 3.3/3 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. 3.3/4 [Note: ... 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 (possibly not visible) name into an enclosing namespace; these restrictions apply to both regions. ] </std> the above somehow supports your code(both). but it said "may" and "possibly not visible" <std> 3.3.1/5 � for an elaborated-type-specifier of the form class-key identifier if the elaborated-type-specifier is used in the decl-specifier-seq or parameter-declaration-clause of a function defined in namespace scope, the identifier is declared as a class-name in the namespace that contains 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. </std> this one does NOT support your code. since it means "function defined in namespace scope" only. <std> 3.3.1/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 scope and object declarations with the extern specifier at block scope refer to delarations that are members of an enclosing namespace, but they do not introduce new names into that scope. ] </std> this one said "refer to", but not "introduce" I think to accept your code or not is by design. Note that forward declaration in the enclosing namespace is a better solution. -- Best Regards Barry [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: insufficient contextual information Next: unresolved function arguments with required typename |