Access private member of enclosing class from nested one

F

Fedor Rodikov

Could anybody explain me how the following code snippet is compiled?
According to the paragraph 11.8 of C++ standard the nested and
enclosing
classes obey usual access rules, but my compiler doesn't complain.

struct A
{
void foo()
{
B::bar1();
B::bar2( *this );
}

struct B
{
static void bar1()
{
init1();
}
static void bar2( A& a )
{
a.init2();
}
};

private:
static void init1() {}
void init2() {}
};

int main()
{
A a;
a.foo();
}

Thanks in advance!
 
K

Kai-Uwe Bux

Fedor said:
Could anybody explain me how the following code snippet is compiled?
According to the paragraph 11.8 of C++ standard the nested and
enclosing
classes obey usual access rules, but my compiler doesn't complain.

struct A
{
void foo()
{
B::bar1();
B::bar2( *this );
}

struct B
{
static void bar1()
{
init1();
}
static void bar2( A& a )
{
a.init2();
}
};

private:
static void init1() {}
void init2() {}
};

int main()
{
A a;
a.foo();
}

Access rules for nested classes have been recognized as a language defect:

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#45

Your compiler aparently implements the proposed resolution, which is also
reflected in the wording of the proposal n3291 for C++0X.


Best,

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top