Topic: Nested Class Question:


Author: jmz@mail.utexas.edu (Jeriad Zoghby)
Date: 1998/03/09
Raw View
Nested Class Question:
I have the following line of code
 Enclosing::a = new Nested[_value];
Enclosing is the enclosing class and Nested is a nested class within Enclosing.
However, in my constructor for the nested class, I need a private member value from the enclosing class.
Since I am constructing an array, I can't pass the argument.
Does anyone know how I can do this?
In particular,
I need to know how a nested class can access a private member of its enclosing class.
Thanks,
Jeriad Zoghby
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Matt Seitz" <mseitz@meridian-data.com>
Date: 1998/03/10
Raw View
Jeriad Zoghby wrote in message <6e0e15$kq9$2@geraldo.cc.utexas.edu>...
>I need to know how a nested class can access a private member of its
enclosing class.

The only way I know is to make the nested class a friend of the enclosing
class and then passing the nested class a pointer to the enclosing class
(See Section C.11.3 in THE C++ PROGRAMMING LANGUAGE, Third Edition).   But
that won't help you in this case, because you can't pass a parameter to the
constructor.  You will have to construct the array elements without using
the member of the enclosing class.  Then you can call a seperate function to
initialize the elements.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: sorry@but.spammed.out (Howard Hinnant)
Date: 1998/03/10
Raw View
In article <6e0e15$kq9$2@geraldo.cc.utexas.edu>, jmz@mail.utexas.edu
(Jeriad Zoghby) wrote:

> In particular,
> I need to know how a nested class can access a private member of its
enclosing class.

class Enclosing {
   class Nested {
   };
   friend class Nested;
};

-Howard
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]