This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
local class and scoping
- To: gcc at gcc dot gnu dot org
- Subject: local class and scoping
- From: Martin Bachtold <martinb at coyotesystems dot com>
- Date: Fri, 19 Nov 1999 12:15:16 -0800
- Organization: Coyote Systems, Inc.
Dear gcc-gurus,
I think I have stumbled on an issue with scoping and local classes. All
compilation is done on gcc-2.95.2. Consider the following short example:
// --------------------------------------------------------
class a {
public:
a() {}
private:
static int sA;
class init {
public:
init();
};
};
int a::sA;
a::init::init() {
sA = 5; // access to static member of enclosing class.
};
int main(int, char**) {
a objA;
return 0;
}
// --------------------------------------------------------
this compiles fine, i.e., it allows the constructor a::init::init() to
access the private static member a::sA of the enclosing class. However,
if I change the access to a::sA such that the full scope path is
specified, access to the sA member is denied. This is the case in the
following code, where only the one line has been changed:
// --------------------------------------------------------
class a {
public:
a() {}
private:
static int sA;
class init {
public:
init();
};
};
int a::sA;
a::init::init() {
a::sA = 5; // access to static member of enclosing class.
};
int main(int, char**) {
a objA;
return 0;
}
// --------------------------------------------------------
I' not sure if any of this is legal c++, but i think that either both
or none of the above should work, since they are doing exactly the same
thing.
Regards, Martin.
--
___________________________________________________________________________
Martin Bächtold
Coyote Systems, Inc.
2740 Van Ness Ave. #210, San Francisco, CA 94109
Tel. +1 (415) 346-4223 x14;
Fax. +1 (415) 346-6282; email: martinb@coyotesystems.com
___________________________________________________________________________