Topic: Nested classes and access control


Author: swf@elsegundoca.ncr.com (Stan Friesen)
Date: 1995/07/06
Raw View
In article <terry.804978925@uivlsi.csl.uiuc.edu>, terry@uivlsi.csl.uiuc.edu (Terry Lee) writes:
|> --------------------
|> class A {
|> private:
|>     class D;   // defined later
|>
|>     class B {
|>  friend class D;  // is this legal?  My guess is yes.
|>     };

I believe so, the scope of D is everything in A, including nested classes.
|>
|>     class C : private B { // is this legal?  My guess is no.

I do not see why this should be a problem.  The base class is defined
at the point of declaration, and is in scope.

|>     public:
|>  void func(B& b); // is this legal?  My guess is no.
|>     };

The only possible problem here is the fact that B is private, which may
make it inaccessible to a nested class.

|>
|>     class D {
|>     public:
|>  void func(B& b); // is this legal?  My guess is yes.
|>     };

Ditto here - if the previous example is not legal, neither is this one.
|> };
|>

--
swf@elsegundoca.attgis.com  sarima@netcom.com

The peace of God be with you.





Author: terry@uivlsi.csl.uiuc.edu (Terry Lee)
Date: 1995/07/05
Raw View
 I've read the ISO/ANSI C++ Draft, but I'm not sure how to interpret
the following cases of nested class access control.  Sun's C++ 4.0 seems
particularly picky while other compilers seem more lenient.  Thanks for any
clarification.

--------------------
class A {
private:
    class D;   // defined later

    class B {
 friend class D;  // is this legal?  My guess is yes.
    };

    class C : private B { // is this legal?  My guess is no.
    public:
 void func(B& b); // is this legal?  My guess is no.
    };

    class D {
    public:
 void func(B& b); // is this legal?  My guess is yes.
    };
};

--
Terry Lee (terry@uivlsi.csl.uiuc.edu)
Coordinated Science Lab
University of Illinois