Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Oct 1996 22:54:07 -0600 (MDT)
From:      Nate Williams <nate@mt.sri.com>
To:        hackers@freebsd.org
Cc:        Nate Williams <nate@mt.sri.com>, mrs@sygnus.com
Subject:   Re: C++ question
Message-ID:  <199610180454.WAA22620@rocky.mt.sri.com>
In-Reply-To: <3266CD1E.41C67EA6@fsl.noaa.gov>
References:  <199610172119.PAA20617@rocky.mt.sri.com> <3266AE63.41C67EA6@fsl.noaa.gov> <199610172209.QAA21050@rocky.mt.sri.com> <3266CD1E.41C67EA6@fsl.noaa.gov>

next in thread | previous in thread | raw e-mail | index | archive | help
class foo {
  private:
    struct A {
      int myint;
    }

    struct B {
      A *ptr;      // Disallowed in the C++ standard
    }
};

> [ Sun's ] compiler notes explicitly (well, not so explicitly) say
> that newer C++ standards don't allow this.

Mike Stump (who is the C++ standards guru for Cygnus) responded with the
following:

Sun's compiler is correct.  To access it, you must say it is a friend:

  11.8  Nested classes                               [class.access.nest]

1 The  members of a nested class have no special access to members of an
  enclosing class, nor to classes or functions that have granted friend-
  ship  to  an  enclosing class; the usual access rules (_class.access_)
  shall be obeyed.  The members of an enclosing class  have  no  special
  access   to  members  of  a  nested  class;  the  usual  access  rules
  (_class.access_) shall be obeyed.  [Example:
          class E {
              int x;
              class B { };
              class I {
                  B b;            // error: E::B is private
                  int y;
                  void f(E* p, int i)
                  {
                      p->x = i;   // error: E::x is private
                  }
              };
              int g(I* p)
              {
                  return p->y;    // error: I::y is private
              }
          };
   --end example]

So, in order to be fully conforming the code could be written as follows:
class foo {
  private:
    struct A {
      int myint;
    }

    // The C++ standard requires the friend stuff
    struct B;
    friend struct B;

    struct B {
      A *ptr;      // Disallowed in the C++ standard
    }
};

Thanks to all, especially Mike who provided both the validation of the
Sun compiler and the solution.



Nate



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610180454.WAA22620>