access rules and nested classes

J

John Harrison

The following example (adapted from standard, section 11.8.1)

class E
{
int x;
class I
{
void f(E* p, int i)
{
p->x = i; // error
}
};
};

is illegal because nested class I has no special access to enclosing class
E. E::x is private and therefore p->x is an access error.

Yet Comeau C++, gcc 3.2 and Visual C++ 7.1 all compile it. What is going on?
Has the standard changed recently?

john
 
A

Ashok Viswanathan

It is a bug in these compilers. HP's aCC compiler gives the expected error.
The other vendors are being milder.
 
J

John Harrison

David White said:
That's quite a document. I recently decided to part with $18 for the
standard. Can I get my money back? :) I wonder how many of the
standard-specialists who post here are up with all this.

DW

I expect most are at least aware of the defect reports. A handy summary of
the important ones would be useful though.

Most of the time I rely on my intuition and experience to answer questions
about C++, thinking that if its an area I don't know anything about then
I'll at least know I don't know. I've made quite a few mistakes recently
though, mostly caused by the language having changed in recent years.

john
 
L

llewelly

John Harrison said:
I expect most are at least aware of the defect reports. A handy summary of
the important ones would be useful though.

Most of the time I rely on my intuition and experience to answer questions
about C++, thinking that if its an area I don't know anything about then
I'll at least know I don't know. I've made quite a few mistakes recently
though, mostly caused by the language having changed in recent years.

Note a large portion of the known issues (but, strangely, not #45,
though its resolution has been stable since 04/01) were resolved
in time for C++2003. The 2003 standard should be availible soon.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top