Hello I have this code with a compiler error (error is from Microsoft Visual Studio 2008):
class B {
protected:
int b;
};
class A : public B {
public:
void foo() { &B::b; }
// error C2248: 'B::b' : cannot access protected member declared in class 'B'
};
while this code is error free:
class B {
protected:
int b;
};
class A : public B {
public:
void foo() { &(B::b); }
};
The two snippets seem to me equivalent based on my knowledge of the precedence of operators, because ::
has an higher precedence than &
(see for example table 2 at page 137 of "JOINT STRIKE FIGHTER AIR VEHICLE C++ CODING STANDARDS FOR THE SYSTEM DEVELOPMENT AND DEMONSTRATION PROGRAM" )
But they are different... I think it is something related to "pointer-to-data-member" but I do not know how does it fit with the operators precedence.
Any explanation?