private forward declare, public class. What does the standard say?

D

Daniel T.

class A {
class B;
// ... later in the code
public:
class B { };
};

I have one compiler telling me that class A::B is inaccessible outside
of A, and another compiler accesses it just fine. Which is correct
according to the standard?
 
K

Kai-Uwe Bux

Victor said:
Daniel said:
class A {
class B;
// ... later in the code
public:
class B { };
};

I have one compiler telling me that class A::B is inaccessible outside
of A, and another compiler accesses it just fine. Which is correct
according to the standard?

Both. Your program is ill-formed. 11.1/3:

"When a member is redeclared within its class definition, the access
specified at its redeclaration shall be the same as at its initial
declaration. [Example:
struct S {
class A;
private:
class A { }; // error: cannot change access
};
-end example]"

Since your program is ill-formed, the compiler is free to compile it
as it sees fit.

Just a nit: that looks like a diagnosable rule to me, in which case the
compiler has to issue a diagnostic as per [1.4/2] and _then_ can go on an
compile the program anyway as per [1.4/8].


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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top