[C++ bug] access control for types
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Thu Feb 10 15:22:00 GMT 2000
> Derived::Nested is a friend of Derived (I see your comment in is_friend_p
> about this being an amendment to the standard). Base::Some_t is accessible
> in Derived. I think the third option of [11.2]/4 applies. [11.5] does not
> apply, as Some_t is not a non-static member (footnote 102 clarifies that).
Hi Nathan,
I believe your code is wrong. The 'naming class' of Some_t is
Derived::Nested, not Derived. Since Derived::Nested has no
relationship to Base, the access is ill-formed. Please note that this
is similar to private members of the outer class: you can't access
them in a nested class, either.
To correct your example, you can write
class Base
{
protected:
typedef int Some_t;
};
class Derived : Base
{
protected:
class Nested;
friend class Nested;
struct Nested
{
void Foo (Base::Some_t);
void Bar (Base::Some_t) {}
};
};
void Derived::Nested::Foo (Base::Some_t) {}
As you point out, g++ is still wrong: the declaration of
Derived::Nested::Base is ill-formed (as is the declaration of Foo).
Regards,
Martin
More information about the Gcc-bugs
mailing list