Topic: Access to Nested Classes Question


Author: Dwayne Moore <dwayne_moore@my-deja.com>
Date: 1999/10/24
Raw View
In section 11.8, class.access.nest, the following example is given:

class C {
        class A { };
        A *p;
        class B : A
        {
                A    *q;
                C::A *r;
                B    *s;
                C::B *t;        // error, C::B is inaccessible
        };
};

Does the fact that C::B is inaccessible in the above example imply
that it is inaccessible in the following example:

class C   {
    class B {
       void  foo(B&);
    };
};

void C::B::foo(C::B& bar) { return; }

Some compilers give an error saying that the private member C::B cannot
be accessed while others do not.


Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: Darin Adler <darin@bentspoon.com>
Date: 1999/10/25
Raw View
Dwayne Moore <dwayne_moore@my-deja.com> wrote:

> Does the fact that C::B is inaccessible in the above example imply
> that it is inaccessible in the following example:
>
> class C   {
> class B {
> void  foo(B&);
> };
> };
>
> void C::B::foo(C::B& bar) { return; }
>
> Some compilers give an error saying that the private member C::B cannot
> be accessed while others do not.

I'm pretty sure that it is inaccessible. Instead you must write:

    void C::B::foo(B& bar) { }

The above works because of the rules about scope of parameter declarations.

But what about this case?

    class C {
        class B {
            B foo();
        }
    }

    C::B C::B::foo() { return *this; }

Is this legal C++ or not? If not, how can you declare the return type for
this version of foo.

    -- Darin
---
[ 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: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/10/25
Raw View
Dwayne Moore wrote:

> In section 11.8, class.access.nest, the following example is given:

[ sniped ]

> Does the fact that C::B is inaccessible in the above example imply
> that it is inaccessible in the following example:

[ sniped ]

Congratulation ! You have discoved that access checking on
members classes is broken. You have basically two choices:
- come back next year to see if things are better
- [committee members only] work on the problem to fix it

--

Valentin Bonnard
---
[ 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              ]