As a result of trial and error, I found a solution that makes sense. Even if it is an inherited element of the base class that you are pointing to, the pointer must still be a member pointer of the Derived class. So the following code works:
include <stdio.h>
class Base
{
protected:
int foo;
int get_foo() { return foo; }
};
class Derived : public Base
{
public:
void bar()
{
int Derived::* i = &Derived::foo;
this->*i = 7;
printf("foo is %d\n", get_foo());
}
};
int main()
{
Derived d;
d.bar();
}
If the Base elements are restricted as private, you get the expected access error.