Access to members of protected base class
Hello all.
This won't compile:
Code:
#include <iostream>
using namespace std;
class B
{
public:
int a;
};
class D: protected B
{
};
class E: public D
{
void f(D* pD)
{
B* pB = pD;
pD->a = 7;
}
};
int main()
{
}
the problem being that B::a is inaccessible in the line pD->a = 7;.
Can anyone explain why this is the case? Is it because member functions of E can access protected (and public) members of the B and D parts of E objects only, and the compiler can't know whether pD points to an E object (as opposed to an object of, say, class F: D{}; )?
Thanks.