Article View: comp.std.c++
Article #511Names introduced in friend decls
From: Daniel Edelson
Date: Sun, 16 Sep 1990 20:48
Date: Sun, 16 Sep 1990 20:48
68 lines
2590 bytes
2590 bytes
Section 9.1 of the AT&T C++ Language System Release 2.1
Product Reference Manual (select code 307-159)
says: ``If a class mentioned as a friend has not been declared
its name is entered into the same scope as the name of the class
containing the friend declaration.''
This means that the semantics of a name declared as a friend
differ for classes and functions.
For example:
class outer {
class inner {
private:
friend class cl; /* cl is a friend class */
friend void fu(); /* fu is a friend function */
};
class cl { }; /* this IS a friend class */
void fu() { } /* this is NOT a friend function */
};
class cl { }; /* this is NOT a friend class */
void fu() { } /* this IS a friend function */
Presumably this distintion became necessary with the introduction
of local and nested classes, there are no local functions or functions
nested in functions, and functions nested in classes have special
meaning.
The above scenario is how I interpret the rules as outlined in the ARM.
It would be possible to define the ``friend void fu()'' declaration
from the above example as declaring that outer::fu() is a friend
of inner. This actually seems consistent and natural, however it falls
apart when inner is a local class.
I suggest that the rule be changed back to:
``If a class mentioned as a friend has not been
declared its name is entered into the global scope.''
This is consistent and easy to program with.
There are not special rules setting apart functions and classes.
The current behavior is trivial to obtain as well:
class outer {
class cl;
class inner {
friend class cl;
};
};
If this definition is not adopted then it should be legal to say:
class outer {
class inner {
friend class ::cl;
};
class cl {}; /* Not a friend */
};
class cl { }; /* Yes a friend */
to explicitly declare the global class to be the friend.
Daniel Edelson | ADA --> B1 bomber
daniel@cis.ucsc.edu, or | C --> F15E fighter
...!sun!practic!peren!daniel | C++ --> Space shuttle
Technical Details
Message-ID:
<6931@darkstar.ucsc.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!bionet!agate!darkstar!terra.ucsc.edu!danielShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!bionet!agate!darkstar!terra.ucsc.edu!daniel From: daniel@cis.ucsc.edu (Daniel Edelson) Newsgroups: comp.std.c++ Subject: Names introduced in friend decls Message-ID: <6931@darkstar.ucsc.edu> Date: 16 Sep 90 20:48:41 GMT Sender: usenet@darkstar.ucsc.edu Reply-To: daniel@cis.ucsc.edu (Daniel Edelson) Organization: University of California, Santa Cruz Lines: 68