Re: Can nested class members access private members of nesting class?

From: CoolPint (coolpint_at_yahoo.co.uk)
Date: 12/14/03


Date: 13 Dec 2003 20:39:19 -0800

jeffplus@comcast.net (Jeff) wrote in message news:<a81f684.0312131021.1cf6890c@posting.google.com>...
> Is Container the same as List? You've shown the definition of one,
> then accessed a member of the other.

Sorry about the naming. Yes, List is supposed to be Container. I made
an typing error while trying to copy and paste the section of codes.
Since I was getting confused myself, I found a simpler sample which
demonstrate the point I am trying to ask.

According to the books, the code below should not be compiled since
nested class "inner" is accessing private member of nesting class
"enclose" without being declared a friend, but my compiler doesn't say
anything.

I want to know if this is the standard behaviour and I made a wrong
interpretation of the books or it is my compiler doing something
weird.

class enclose
{
  public:
   class inner
   {
     public:
      void f(enclose *e)
      {
  e->x = 1;
  e->y = 2;
  e->z = 3;
      }
   };
   int x;
  protected:
   int y;
  private:
   int z;
};



Relevant Pages

  • Re: Size of a structure : Structure Padding
    ... int i1; // 4 ... According to the rules of structure padding shouldn't the size of the ... it shouldn't be 28 bytes for a 32-bit compiler. ... It may very well be that the second member of your structure, ...
    (comp.lang.c)
  • Re: C++ in ternms of C
    ... >A class has its member variables, ... > int b, c, d; ... >the compiler performs these checks to tell us that our code conforms to the ... >design specification of the class (for example, not changing the member ...
    (microsoft.public.vc.language)
  • Re: Variable length arrays proposal
    ... int length; char data;} String; This would indicate to the compiler that the "data" array will have the length indicated by the "length" member. ... The index should be a structure member of integer type. ... Along with the other comments, even if it went through, the index should be size_t, not int. ...
    (comp.std.c)
  • Re: Can nested class members access private members of nesting class?
    ... List is supposed to be Container. ... > interpretation of the books or it is my compiler doing something ... > int x; ...
    (comp.lang.cpp)
  • Re: Superbasic efficiency question
    ... > have members such as int a, b, c, d, e or a single member such as int ... perhaps the compiler placed the values in registers. ...
    (comp.lang.cpp)