A
Alan Johnson
Consider the following piece of code:
// test.cpp
class B ;
namespace N
{
class A
{
friend class B ;
protected:
int i ;
} ;
}
class B
{
N::A a ;
public:
B() { a.i = 42 ; }
} ;
g++ 3.4.6 will compile this without complaint. g++ 4.1.0, however,
gives the error:
test.cpp: In constructor ‘B::B()’:
test.cpp:9: error: ‘int N::A::i’ is protected
test.cpp:17: error: within this context
If the friend declaration is changed to:
friend class ::B ;
then g++ 4.1.0 also accepts the code.
I am trying to determine which (if either) behavior is correct, but I'm
having trouble locating the relevant section of the standard. Any help
would be appreciated.
// test.cpp
class B ;
namespace N
{
class A
{
friend class B ;
protected:
int i ;
} ;
}
class B
{
N::A a ;
public:
B() { a.i = 42 ; }
} ;
g++ 3.4.6 will compile this without complaint. g++ 4.1.0, however,
gives the error:
test.cpp: In constructor ‘B::B()’:
test.cpp:9: error: ‘int N::A::i’ is protected
test.cpp:17: error: within this context
If the friend declaration is changed to:
friend class ::B ;
then g++ 4.1.0 also accepts the code.
I am trying to determine which (if either) behavior is correct, but I'm
having trouble locating the relevant section of the standard. Any help
would be appreciated.