On 10 mayo, 05:26, sat_a...@[EMAIL PROTECTED]
wrote:
> In the following code, nested class B is accessing private member of
> A. Is this allowed? This code compiles on Comeau online test compiler
> and Visual Studio 2005.
>
> class A
>
> {
> class B
> {
> A* a;
> int bVal;
> B() { bVal = a->aVal; } // This compiles
> };
>
> private:
>
> int aVal;
>
> };
>
> int main(int argc, char** argv) {}
Hello,
According to [class.access.nest]/1 from the standard:
"The members of a nested class have no special access to members of an
enclosing class, nor to cl***** or functions that have granted
friend****p to an enclosing class; the usual access rules (clause 11)
shall be obeyed. The members of an enclosing class have no special
access to members of a nested class; the usual access rules (clause
11) shall be obeyed."
But there is a defect re****t related to this:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#45.
On
compilers that implement the proposed resolution of this defect re****t
[1], nested cl***** are full members of the enclosing class and, as
such, they have full access to it.
[1] g++ is one of them: http://gcc.gnu.org/bugs.html
Regards,
David
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|