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

From: Jeff (jeffplus_at_comcast.net)
Date: 12/13/03


Date: 13 Dec 2003 10:21:45 -0800

Is Container the same as List? You've shown the definition of one,
then accessed a member of the other.

-Jeff

coolpint@yahoo.co.uk (CoolPint) wrote in message news:<159a5c32.0312122340.2074968c@posting.google.com>...
> I read in books that nested class cannot access private members of
> nesting class and vice versa unless they are made friends. Somehow, my
> compiler is letting my nested class member functions access private
> members of nesting class.
>
> template <typename T>
> class Container {
> // NO friendship given to any other
> public:
> class ContainerIterator;
> // other members
> private:
> class Node;
> Node * header;
> Node * tailer;
> int counter;
> };
>
> Nested class Node has all of its members as public so that Container
> members can access them. And then I have the nested Class
> ContainerIterator, which have both public and private parts.
>
> template <typename T>
> class Container<T>::ContainerIterator {
>
> friend class List<T>; // so that List<T> can access private members of
> Iterator
> public:
> // public members
> private:
> List<T>::Node * dummyheader;
> List<T>::Node * ptr;
> ContainerIterator(const List<T> & l , List<T>::LNode * p);
> // private members
> };
>
> I forget to declare ContainerIterator class to be a friend of
> Container class, yet member functions of ContainerIterator can access
> private members of Container class! For example,
> ContainerIterator(const List<T> & l , List<T>::LNode * p)
> {
> dummyheader = l.header; // ! This works! but why?
> ptr = p;
> };
>
> So am I misinterpreting the books or is my compiler not following the
> standard? BTW, I am using g++ 3.2.3. I am quite confused to be honest
> and would appreciate any help very much. Thanks in advance.



Relevant Pages

  • Re: { }
    ... > Consider a universe consisting of only fruits and boxes. ... > this is the same as a set with three members,. ... Well in that case one should speak about Container theory or box ... seems to be the same band always. ...
    (sci.math)
  • Can nested class members access private members of nesting class?
    ... compiler is letting my nested class member functions access private ... members of nesting class. ... Nested class Node has all of its members as public so that Container ...
    (comp.lang.cpp)
  • Re: factory functions & methods
    ... AB> I am creating a container. ... AB> members of the container. ...   def SomeType: ... class CustomType(cA.MemberBase): ...
    (comp.lang.python)
  • Re: Can a machine be placed in multiple OUs
    ... An object can only reside in one 'container' at a time. ... The mapped network drives are usually handled by ... You might want to look into assigning mapped network drives based on group ... membership (for example, the members of the Marketing group get ...
    (microsoft.public.win2000.active_directory)
  • Re: Can nested class members access private members of nesting class?
    ... we are saying about class *Container* with some private members. ... > Nested class Node has all of its members as public so that Container ...
    (comp.lang.cpp)