c++/10668: nested class looks for member variable rather than object

bwood@emc.com bwood@emc.com
Wed May 7 17:39:00 GMT 2003


>Number:         10668
>Category:       c++
>Synopsis:       nested class looks for member variable rather than object
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 07 17:36:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Bob Wood (bwood@emc.com)
>Release:        gcc-3.2.3
>Organization:
>Environment:
Solaris 8
>Description:
When the attached file is compiled with g++, I get this error:
 test.cpp: In constructor 'c1::c2::c2()':
 test.cpp:10: 'class c1::c2' has no member named 'i'

If I remove the line commented "remove for success", no error results.  Because c1::c2 has no access to c1::i, I would expect the compiler to simply reference the global variable i, as it does when the commented line is removed.
>How-To-Repeat:
g++ test.cpp
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="test.cpp"
Content-Disposition: inline; filename="test.cpp"

int i;

class c1 {
public:
  int i;
  friend class c2;
  class c2 {
  public:
    int* y;
    c2() { y = &i; };
  };

  c2 z;
};



More information about the Gcc-bugs mailing list