64 bit g++ version 8.1.0
I declared the functions outside the class (as fb), but tested exactly the same with methods written inside the class.
Thanks Paul Doe for the initial translation.
Code: Select all
class Parent
{
protected:
int i ;
static int j ;
};
int Parent::j = -4 ;
class Child1 : Parent {};
class Child2 : Parent
{
void test( Child2& c2, Parent& p, Child1& c1 );
static void stest( Child2& c2, Parent& p, Child1& c1 );
};
void Child2::test( Child2& c2, Parent& p, Child1& c1 )
{
// non-static protected member access from non-static member procedure
i = 1 ; // OK
this->i = 2 ; // OK
c2.i = 3 ; // OK
//p.i = 4 ; // NOK
//c1.i = 5 ; // NOK
// static protected member access from non-static member procedure
j = 1 ; // OK
this->j = 2 ; // OK
c2.j = 3 ; // OK
p.j = 4 ; // OK
//c1.j = 5 ; // NOK
}
void Child2::stest( Child2& c2, Parent& p, Child1& c1 )
{
// non-static protected member access from static member procedure
c2.i = 3 ; // OK
//p.i = 4 ; // NOK
//c1.i = 5 ; // NOK
// static protected member access from static member procedure
j = 1 ; // OK
c2.j = 3 ; // OK
p.j = 4 ; // OK
//c1.j = 5 ; // NOK
}
//};
int main()
{
return 0 ;
}